Zend framework2 如何在ZF 2中返回文件路径
我有一个表单和一个控制器ZF2。我可以上传文件和其他数据,但我不能将文件的@value of the path@作为字段值写入数据库表。仅在表数据库字段中显示值数组!如何更改控制器或其他位置,并在表的字段中保存文件路径非数组的值?Zend framework2 如何在ZF 2中返回文件路径,zend-framework2,Zend Framework2,我有一个表单和一个控制器ZF2。我可以上传文件和其他数据,但我不能将文件的@value of the path@作为字段值写入数据库表。仅在表数据库字段中显示值数组!如何更改控制器或其他位置,并在表的字段中保存文件路径非数组的值? RestaurantController.php RestaurantForm.php Restaurant.php 你是说你想要用户文件系统上的本地文件路径吗?通常,浏览器不会将该信息提供给服务器。它只发送文件名、mimetype(根据文件扩展名推断)、文件大小和实
RestaurantController.php RestaurantForm.php Restaurant.php
你是说你想要用户文件系统上的本地文件路径吗?通常,浏览器不会将该信息提供给服务器。它只发送文件名、mimetype(根据文件扩展名推断)、文件大小和实际文件内容。很抱歉,我解决了这个问题;)在Restaurant.php中。
$form = new RestaurantForm();
$form->get('submit')->setValue('Добавить ресторан');
$request = $this->getRequest();
if ($request->isPost()) {
$restaurants = new Restaurant();
$form->setInputFilter($restaurants->getInputFilter());
$data= array_merge_recursive(
$this->getRequest()->getPost()->toArray(),
$this->getRequest()->getFiles()->toArray()
);
$form->setData($data);
if ($form->isValid()){
//array_map('unlink', glob('./public/img/restaurants*'));{
$restaurants->exchangeArray($form->getData());
$this->getRestaurantsTable()->saveRestaurant($restaurants);
// Form is valid, save the form!
// Redirect to list of albums
return $this->redirect()->toRoute('zfcadmin/restaurants');
}
}
//else return $this->redirect()->toRoute('zfcadmin');
return array('form' => $form);
}
// File Input
$file = new Element\File('restaurant_thumbnail');
$file->setLabel('Загрузите главный рисунок ресторана')
->setAttribute('id', 'image-file');
$this->add($file);
#version2
// $inputFilter = new InputFilter();
// File Input
//https://github.com/cgmartin/ZF2FileUploadExamples/blob/master/src/ZF2FileUploadExamples/Form/SingleUpload.php
$file = new FileInput('restaurant_thumbnail');
$file->setRequired(true);
$file->getFilterChain()->attachByName(
'filerenameupload',
array(
'target' => './public/img/restaurants/*',
'overwrite' => true,
'use_upload_name' => true,
)
);
$inputFilter->add($file);