2016-04-17 43 views
1

我的代码如下,我无法将图像存储在codeigniter中的特定文件夹中。图像存储数据库表,但不存储在特定路径中。图像没有存储在使用codeigniter的文件夹中

控制器:

if (isset($_FILES['header_image']) && $_FILES['header_image']['name'] != "") { 
        $fileName="header_image_$id"; 
        $ext= end(explode('.',$_FILES['header_image']['name'])); 
        $file_name=$fileName.".".$ext; 
        $this->_upload('uploads/header_images/', "gif|jpg|png|jpeg", "header_image",$file_name); 
        $this->generic_model->updateRecord("blood_tips",array("header_image"=>'uploads/header_images/'.$fileName.".$ext"), array("id"=>$id)); 
    } 


private function _upload($uploadPath,$allowedTypes,$name,$file_name) 
{ 
    $config['file_name'] = $file_name; 
    $config['upload_path'] = $uploadPath; 
    $config['allowed_types'] = $allowedTypes; 
    $config['max_size'] = '100'; 
    $config['max_width'] = '1024'; 
    $config['max_height'] = '768';    
    $this->load->library('upload', $config); 
    if (!$this->upload->do_upload($name)) 
    { 
     return $this->upload->display_errors(); 
    } 
    else 
    { 
     $data = array('upload_data' => $this->upload->data()); 

    } 

} 

回答

0

文件上传参数大于提出的文档不同。

$ config ['upload_path'] ='./uploads/';在路径前注意“./”。

+0

我也做,但没有,, :) – user3436031

+0

代码在这里,你上传的,与修改建议应该正常工作。 如果您可以上传,完成控制器类和完全的表单代码,则可以提供帮助。 – Mobeen

+0

它是否甚至显示由于最后一个条件而导致的错误?或者它也通过,如果条件? – Mobeen

0

TE上传文件中的CI正确的方法,你需要这样的:

$fileName="header_image_$id"; 
    $ext= end(explode('.',$_FILES['header_image']['name'])); 

    $config['upload_path'] = './uploads/header_images/'; 
    $config['file_name']  = $fileName.".".$ext;//The extension provided in the file name must also be an allowed file type. 
    $config['allowed_types'] = 'gif|jpg|png'; 
    $config['max_size']  = 0; 

    $this->load->library('upload', $config); 

    if (! $this->upload->do_upload()) 
    { 
     $error = array('error' => $this->upload->display_errors()); 

     $this->load->view('upload_form', $error); 
    } 
    else 
    { 
     $data = array('upload_data' => $this->upload->data()); 

     $this->load->view('upload_success', $data); 
    } 
相关问题