2016-02-25 97 views
0

我想上傳codeigniter上上傳類文件,但它會引發錯誤,說文件路徑無效。上codeigniter上傳失敗

我打印了$this->upload->data,它沒有顯示文件數據,但是我設置的上傳文件夾存在並顯示在其上。

array(14) { 
    ["file_name"]=> string(0) "" 
    ["file_type"]=> string(0) "" 
    ["file_path"]=> string(36) "homologacao/assets/images/promocoes/" 
    ["full_path"]=> string(36) "homologacao/assets/images/promocoes/" 
    ["raw_name"]=> string(0) "" 
    ["orig_name"]=> string(0) "" 
    ["client_name"]=> string(0) "" 
    ["file_ext"]=> string(0) "" 
    ["file_size"]=> string(0) "" 
    ["is_image"]=> bool(false) 
    ["image_width"]=> string(0) "" 
    ["image_height"]=> string(0) "" 
    ["image_type"]=> string(0) "" 
    ["image_size_str"]=> string(0) "" 
} 

但是,當我得到的$_FILES數據,它顯示上傳的文件數據

array(1) { 
    ["imagem"]=> array(5) { 
     ["name"]=> string(68) "3bf514d6cbb31410ee47e8cbcc79c81588a6740fb4264209a1531077e0fcc0a9.jpg" 
     ["type"]=> string(10) "image/jpeg" 
     ["tmp_name"]=> string(14) "/tmp/phpomUcFo" 
     ["error"]=> int(0) 
     ["size"]=> int(3571) 
    } 
} 

我雙重檢查我的代碼,我想我設置的事情以正確的方式

/*code slice with the upload part */ 

$config['upload_path'] = 'homologacao/assets/images/promocoes/'; 
$config['allowed_types'] = 'png|jpg|gif'; 
$config['max_size'] = '1024'; 
$config['encrypt_name'] = true; 

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

$field_name = 'imagem'; 
if ($this->upload->do_upload($field_name)) { 
    /* do stuff */ 
} else { 
    var_dump($this->upload->data()); 
    var_dump($this->upload->display_errors()); 
    var_dump($_FILES); 

    die(); 
} 

爲什麼文件上傳無法正常工作,我該如何解決?

+0

什麼得到display_errors() – devpro

+0

就像「無效的上傳文件路徑」 –

回答

0

你的文件的路徑應該是這樣的:

$config['upload_path'] = './homologacao/assets/images/promocoes/'; 
+0

沒有運氣。同樣的錯誤在這裏:( –

+0

是你的根目錄中的「homologacao/*」文件夾? –

+0

是的,它是。 也,我試過'$ _SERVER ['DOCUMENT_ROOT']'/ homologacao/assets/images/promocoes/''沒有運氣 –

0

我做到了!

上傳路徑

$config['upload_path'] = $_SERVER['DOCUMENT_ROOT'] . 'homologacao/assets/images/promocoes/'; 

謝謝大家誰幫我試圖弄明白在剛剛設置好的DOCUMENT_ROOT