在codeigniter中上传文件不会将上传文件移动到目标目录

在codeigniter中上传文件不会将上传文件移动到目标目录

问题描述:

I'm trying to upload image using codeigniter. But when I select and upload a file, it don't move to my destination folder.

Here is my controller code.

 if(empty($_FILES['pwd']['name']))
    {
        $error=array(
            'error_img'=>'Image file empty !!!.'
        );
        $this->index();
    }
    else
    {
        $type=explode('.',$_FILES["pwd"]["name"]);
        $type=$type[count($type)-1];
        $url="./photos/".uniqid(rand()).'.'.$type;
        if(in_array($type,array("jpg","jpeg","gif","png")))
        if(is_uploaded_file($_FILES["pwd"]["tmp_name"]))
        if(move_uploaded_file($_FILES["pwd"]["tmp_name"],$url))
        return $url;
        return "";
    }

CodeIgnier has an Upload Library. follow codeigniter upload documentation

public function do_upload()
{
  $config['upload_path']          = './uploads/';
  $config['allowed_types']        = 'gif|jpg|png';
  $config['max_size']             = 100;
  $config['max_width']            = 1024;
  $config['max_height']           = 768;
  $this->load->library('upload', $config);
  $this->upload->do_upload('userfile'):
}

Make sure you follow correct folder path.