问题
I'm creating a library as part of a project and one of the methods is a wrapper for the upload helper.
The method:
public function upload(){
echo "Doing upload";
$config['upload_path']= RESOURCE_PATH . "Downloads";
$config['allowed_types']='pdf|doc';
$config['max_size']='10000';
//echo $config['upload_path'];
$this->CI->load->library('upload',$config);
if(!$this->CI->upload->do_upload()){
echo "Couldn't do the upload";
echo $this->CI->upload->display_errors();
echo $config['upload_path'];
}
else{
echo "Could do the upload";
}
}
I've checked the directory permissions of the Downloads folder and that it exists but I'm getting the following error: "The upload path does not appear to be valid."
How do I resolve this issue?
EDIT:: I created a symlink so my directory strucutre really looks like:
www -> /home/user/Dropbox/www/appname
Note about variables used:
$this->CI = &get_instance(); // Defined in custom library class
define('RESOURCE_PATH', APPPATH . 'views/resources/'); // Defined in constants.php
回答1:
Figured out the idiotic problem.
I was autoloading the library and some how when I was trying to initialize the configuration by $this->load->library('upload', $config); it wouldn't do so.
Instead I put my config files in config/upload.php
The other method to do so would have been $this->upload->initialize($config);
See this answer.
回答2:
Add this line
$this->CI->upload->initialize($config);
after
$this->CI->load->library('upload',$config);
来源:https://stackoverflow.com/questions/16080519/why-is-my-upload-path-invalid-codeigniter-library