file upload in cakephp 2.3

前端 未结 4 1672
庸人自扰
庸人自扰 2020-12-18 01:11

I\'m new in cakephp and i\'m trying to create a simple file upload with cakephp 2.3 here is my controller

public function add() {
    if ($this->request-&         


        
4条回答
  •  眼角桃花
    2020-12-18 01:43

    ..ensure the documents directory already exists and check you have permissions to write to it? If it doesnt exist create it or in your code check if it exists and create it if it is not there: example of code that will check if the directory is there or not and create it then upload the file-

    $dir = WWW_ROOT. DS . 'documents';
     if(file_exists($dir) && is_dir($dir))
     {
        move_uploaded_file($this->data['posts']['doc_file']['tmp_name'],$filename);  
     }
     elseif(mkdir($dir,0777))
     {
      move_uploaded_file($this->data['posts']['doc_file']['tmp_name'],$filename);  
      }
    

    also ensure you are not uploading a blank/empty file - it might fail.

提交回复
热议问题