我是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