【发布时间】:2015-12-12 17:52:03
【问题描述】:
我无法在 CakePHP 中将文件从一个文件夹上传到另一个文件夹。这是我的代码。
首先我加载了插件并将这段代码添加到ProductsTable.php
$this->addBehavior('Xety/Cake3Upload.Upload', [
'fields' => [
'productimg_file' => [
'path' => 'uploads/avatar/:id/:md5'
]
]
]);
然后我添加了我的add.cpt
<?php
echo $this->Form->input('productcode');
echo $this->Form->input('productname');
echo $this->Form->input('productprice');
echo $this->Form->input('quantity');
echo $this->Form->input('productdesc');
echo $this->Form->input('productimg_file',['type' => 'file']);
?>
文件仍然没有移动到webroot 目录。
在此处输入代码 公共函数添加() {
$product = $this->Products->newEntity();
if ($this->request->is('post')) {
$product = $this->Products->patchEntity($product, $this->request->data);
if ($this->Products->save($product)) {
$this->Flash->success(__('The product has been saved.'));
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error(__('The product could not be saved. Please, try again.'));
}
}
$this->set(compact('product'));
$this->set('_serialize', ['product']);
}
【问题讨论】:
-
它是否抛出任何错误?请编辑您的问题并添加您的
ProductsController::add()操作和任何其他相关代码。
标签: cakephp cakephp-3.1 cakephp-3.x