这是我用于将图像上传到SQL Server的方法
public function add()
{
$category = $this->Categories->newEntity();
if ($this->request->is('post')) {
if(!empty($this->request->getData['image']['name'])){
$fileName = $this->request->getData['image']['name'];
$uploadPath = 'img/';
$uploadFile = $uploadPath.$fileName;
if($move_uploaded_file($this->request->getData['image']['tmp_name'],$uploadFile)){
$this->request->getData['image']=$fileName;
}
}
$category = $this->Categories->patchEntity($category, $this->request->getData());
if ($this->Categories->save($category)) {
//$this->Flash->success(__('The category has been saved.'));
return $this->redirect(['controller' => 'users','action' => 'index']);
}
// $this->Flash->error(__('The category could not be saved. Please, try again.'));
}
$this->set(compact('category'));
}
在add.ctp中,代码为
<?= $this->Form->create($category,array('type'=> 'file')); ?>
所以错误是提供的值无效,请帮忙