Reputation: 2860
I am creating some file upload functionality utilizing the upload library within the Code Igniter framework and I am having an issue where I keep on getting an error back stating that my file upload path is incorrect. I have checked many times and there is no issue with the file structure and the files definitely exist.
Here is my model upload code (I am dieing to check where I am within the process):
class Gallery_model extends CI_Model {
var $gallery_path;
function __construct() {
parent::__construct();
$this->gallery_path = realpath(APPPATH . '../images/profileImages');
//$this->gallery_path = realpath($this->config->base_url() . 'images/profileImages');
}
public function doUpload() {
$config = array(
'allowed_types' => 'jpg|jpeg|png|gif',
'upload_path' => $this->gallery_path
);
$this->load->library('upload', $config);
if($this->upload->do_upload()) {
$data = array('upload_data' => $this->upload->data());
die(print_R($data));
} else {
$error = array('error' => $this->upload->display_errors());
die(print_R($error));
}
}
}
My images folder is outside of the application and is called 'images', which contains a folder called 'profileImage' where I want this files to save. I get the following error:
'The upload path does not appear to be valid.'
I can't for the life of me figure out why this path is not working when it definitely exists. Does anyone have any ideas? Thanks
Upvotes: 0
Views: 2322
Reputation: 6016
Is your images folder in the web root? If is this should work
$this->gallery_path = './images/profileImages/';
Upvotes: 1
Reputation: 76666
Codeigniter will only return that error message if $config['upload_path']
is blank or the php command is_dir($config['upload_path'])
returns false. Check to make sure the 'uploads' folder is in the same directory as main index.php file and that the directory name is the same case
Upvotes: 3