我是cakephp和php的新手,我试图在上传文件后将文件保存在文件夹中。我正在关注本教程http://www.tuxradar.com/content/cakephp-tutorial-build-file-sharing-application。非法字符串偏移'错误'
我有这样的代码:
function uploadFile() {
$file = $this->data['Upload']['file'];
if ($file["error"] === UPLOAD_ERR_OK) {
$id = String::uuid();
if (move_uploaded_file($file['tmp_name'], APP.'uploads'.DS.$id)) {
$this->data['Upload']['id'] = $id;
$this->data['Upload']['user_id'] = $this->Auth->user('id');
$this->data['Upload']['filename'] = $file['name'];
$this->data['Upload']['filesize'] = $file['size'];
$this->data['Upload']['filemime'] = $file['type'];
return true;
}
}
return false;
}
,它是给我这个错误:Illegal string offset 'error'
我想这"var_dump($file["error"]);"
和它返回string(1) "1"
什么是我的问题,我如何解决。
感谢
查看$ this-> data ['Upload']或检查数组键'upload'。 – Knase 2014-11-04 21:50:45
我刚刚试图删除['上传'] ['文件']和var_dumb给我阵列(2){[“上传”] =>数组(3){[“标题”] =>字符串(2)“ mm“[”description“] => string(0)”“[”file“] => string(24)”15您不知道Me.mp3“} [”User“] => array(1){ [“User”] => array(1){[0] => string(1)“3”}}}。现在我有一个问题:未定义的索引:错误 – user3768804 2014-11-04 22:07:55
你用过吗?<?php echo $ this-> Form-> create('Upload',array('type'=>'file'));?>'? – Abhishek 2014-11-05 06:17:57