在Codeigniter中上载图像显示错误上载路径似乎无效

nid*_*hin 3 codeigniter

$config['upload_path'] = site_path().'photos/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = '2048';
$this->load->library('upload', $config);    
if ( ! $this->upload->do_upload())
{ 
    $this->data['alert'] = $this->upload->display_errors();                     
    $this->load->view('profile/photo', $this->data);
}   
else
{
    $upload_data = $this->upload->data();

    $filename = $upload_data['file_name'];
    $width = $upload_data['image_width'];
    $height = $upload_data['image_height'];
    $config1 = array();
    $this->load->library('image_lib');
    $config1['source_image'] = site_path().'photos/'.$filename;


    $this->remove_existing_file($this->session->userdata('user_id'));
    $this->Profile_model->savephoto('Edit', $filename );
    redirect('/profile/photo');
}
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

上传路径似乎无效.

Wes*_*rch 8

发生此错误的原因只有几个:

  1. 该目录site_path().'photos/'不存在,请尝试运行is_dir()以确保它存在.
  2. 该目录存在但不可写.确保已在目录上设置适当的权限.尝试运行is_writable()以确保.
  3. 您要使用的目录存在,但您尚未将其正确表示到上载库.尝试使用带有正斜杠的绝对路径,类似于"用户指南"中的示例.

除此之外,没有我能想到的解释.以下是验证路径的CI代码(Upload类的一部分):

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;
}
Run Code Online (Sandbox Code Playgroud)

更新:

根据你的意见,试试这个,让我们看看在进入下一步调试之前会发生什么:

$config['upload_path'] = './community/photos/';
Run Code Online (Sandbox Code Playgroud)