php - Illegal string offset 'error' -
i new cakephp , php , im trying save file in folder after uploading it. next tutorial http://www.tuxradar.com/content/cakephp-tutorial-build-file-sharing-application.
i have code:
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']; homecoming true; } } homecoming false; }
and giving me error: illegal string offset 'error'
tried "var_dump($file["error"]);"
, returning string(1) "1"
problem , how can solve it. thanks
i think problem because download didn't cause error why error index isn't present, why suggest write in test :
if(isset($file['error']) && $file['error'] === upload_err_ok){ //your code here }
i hope helpful.
php cakephp file-upload
No comments:
Post a Comment