Uploading an image in Codeigniter shows error The upload path does not appear to be valid

前端 未结 10 1584
独厮守ぢ
独厮守ぢ 2020-12-18 11:54
$config[\'upload_path\'] = site_path().\'photos/\';
$config[\'allowed_types\'] = \'gif|jpg|png|jpeg\';
$config[\'max_size\'] = \'2048\';
$this->load->library(\         


        
相关标签:
10条回答
  • 2020-12-18 12:37

    Hi on server you can connect with filezilla and right click on folder and change File Attributes

    0 讨论(0)
  • 2020-12-18 12:37

    I know this has already been answered. Even I had difficulty trying to upload files. But in my case the issue was that I had the CodeIgniter application in a folder outside of /var/www and the index page in the www folder (mainly as a security measure).

    The uploads folder should be in the /var/www folder that contains the index.php file. This is what I had to do. The next thing is to give 777 permissions to the uploads folder.

    0 讨论(0)
  • 2020-12-18 12:41

    There's only a few reasons for this error to occur:

    1. The directory site_path().'photos/' does not exist, try running is_dir() to ensure that it does.
    2. The directory exists but is not writable. Make sure you have set the appropriate permissions on the directory. Try running is_writable() to make sure.
    3. The directory you want to use exists, but you have not represented it properly to the Upload library. Try using an absolute path with a trailing forward slash, similar to the example in the User Guide.

    Beyond that, there is no explanation I can think of. Here is the CI code that validates the path (part of the Upload class):

    public function validate_upload_path()
    {
        if ($this->upload_path == '')
        {
            $this->set_error('upload_no_filepath');
            return FALSE;
        }
    
        if (function_exists('realpath') AND @realpath($this->upload_path) !== FALSE)
        {
            $this->upload_path = str_replace("\\", "/", realpath($this->upload_path));
        }
    
        // This is most likely the trigger for your error
        if ( ! @is_dir($this->upload_path))
        {
            $this->set_error('upload_no_filepath');
            return FALSE;
        }
    
        if ( ! is_really_writable($this->upload_path))
        {
            $this->set_error('upload_not_writable');
            return FALSE;
        }
    
        $this->upload_path = preg_replace("/(.+?)\/*$/", "\\1/",  $this->upload_path);
        return TRUE;
    }
    

    Update:

    Per your comments, try this instead and let's see what happens before moving to the next step of debugging:

    $config['upload_path'] = './community/photos/';
    
    0 讨论(0)
  • i think problem can be solve by using

    $config['upload_path'] ='./photos/';
    

    instead of

    $config['upload_path'] = site_path().'photos/';
    
    0 讨论(0)
提交回复
热议问题