我对此完全感到困惑。我正在尝试上传图片,但我一直收到这个错误,我搜索了网站,我发现了大量相同的问题,但我无法让任何这些解决方案为我工作。
我的模型中有这个代码,应该将图像数组转换为字符串。
public function processImageUpload($check = array()) {
if (!is_uploaded_file($check['image']['tmp_name'])){
return FALSE;
}
if (!move_uploaded_file($check['image']['tmp_name'], WWW_ROOT .
'img' . DS . 'uploads' . DS . $check['image']['name'])){
return FALSE;
}
$this->data[$this->alias]['image'] = 'uploads' . DS .
$check['image']['name'];
return TRUE;
}
接下来,我有PostsController
public function add() {
if($this->request->is('post')) {
$this->request->data['Post']['username']= $this->Auth->user('username');
$this->Post->create();
$data = $this->request->data['Post'];
if (!$data['image']['name']){
unset($data['image']);
}
if($this->Post->save($data)) {
$this->Session->setFlash(__('Your post has been saved.'));
return $this->redirect(array('action'=>'index'));
}
$this->Session->setFlash(__('Unable to add your post.'));
}
}
然后我的表单上传了文件。
echo $this->Form->create('Post', array('type' => 'file'));
echo $this->Form->input('title');
echo $this->Form->input('movie');
echo $this->Form->input('category');
echo $this->Form->input('description' , array('rows'=>'2'));
echo $this->Form->input('image', array('type' => 'file'));
echo $this->Form->end('Submit Article for Review');
那么为什么我的模型中的函数没有将数组转换为字符串?我在这里不理解什么?