2012-04-01 78 views
0

我與此戰鬥已經1個半小時,但無法找到問題。我使用笨和上傳功能,但它總是失敗上傳 -沒有圖片上傳在codeigniter

控制器 -

// Uploads the picture to server 
    public function uploadPicture() 
    { 
    $this->load->helper(array('form', 'url')); 
    $this->load->helper('url'); 
     $config['upload_path'] = './images/pictures/'; 
     $config['allowed_types'] = 'gif|jpg|png'; 
     $config['max_size'] = '700'; 
     $config['max_width'] = '1024'; 
     $config['max_height'] = '768'; 

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

     $this->upload->do_upload(); 

     if (! $this->upload->do_upload()) 
     { 
      $data = array('upload_data' => $this->upload->data());  

      var_dump($data); 
     //redirect('/profile/changePicture', 'refresh'); 
     } 
     else 
     { 
     redirect('/profile/changePicture', 'refresh');    
     } 
    } 

視圖 -

<form class="fix-this form" method="post" action="/savieno/profile/uploadPicture" enctype="multipart/form-data"> 
        <div class="formfield">      
         <label id="current-password-error" class="input-error" style="display: none;"></label>   
         <span class="profile">Tava bilde: </span>         
         <input id="picture" name="picture" class="with-label" style="width: 270px;" type="file" placeholder="Tava bilde" /> 
         <label>*</label> 
    </div>      
        <input type="submit" id="submit" value="Labot Profilu" name="edit" class="fix-this" />   
    </form> 

後,我選擇沒有圖像,或者如果我選擇圖片,它給我var_dump與detials -

array 
    'upload_data' => 
    array 
     'file_name' => string '' (length=0) 
     'file_type' => string '' (length=0) 
     'file_path' => string './images/pictures/' (length=18) 
     'full_path' => string './images/pictures/' (length=18) 
     'raw_name' => string '' (length=0) 
     'orig_name' => string '' (length=0) 
     'client_name' => string '' (length=0) 
     'file_ext' => string '' (length=0) 
     'file_size' => string '' (length=0) 
     'is_image' => boolean false 
     'image_width' => string '' (length=0) 
     'image_height' => string '' (length=0) 
     'image_type' => string '' (length=0) 
     'image_size_str' => string '' (length=0) 

可能是什麼問題?

+0

它是如何失敗?怎麼了?你有錯誤嗎? – kba 2012-04-01 15:55:57

+0

沒有錯誤,它只是加載var_dump ...檢查控制器,它說如果上傳失敗,然後加載var_dump,否則重定向。 ;/ – 2012-04-01 16:04:18

+0

你正在做'$ this-> upload-> do_upload()'兩次。 – kba 2012-04-01 16:12:52

回答

0

$config['upload_path'] = './images/pictures/';請確保您寫入的路徑是正確的,並且具有將文件寫入到的適當777權限。

另外,正如克里斯蒂安寫道,你正在做$this->upload->do_upload();上傳部分兩次。

檢查錯誤,你可以這樣做:

<?php 
if(!$this->upload->do_upload())   
{ 
    echo $this->upload->display_error(); 
    return FALSE; 
} 
else 
{ 
    $data = $this->upload->data(); 
    return TRUE; 
} 
+0

哦,是的,我知道,那只是爲了檢查,如果它給出任何錯誤,但它不會。好吧,檢查它兩次,如果它是在本地主機上,我可以將全部內容添加到http:// localhost/images/pictures /?另外,如果我在本地主機上檢查它,我是否真的需要設置權限? – 2012-04-01 16:31:21

+0

您必須在您測試的任何位置設置權限。只需在CI項目的主文件夾中創建一個'uploads'文件夾,設置權限並重試。 – 2012-04-01 16:38:33

+0

嗯,現在我該如何設置本地主機的權限? :P我正在使用Windows 7,並且我沒有在本地主機上設置服務器,所以我必須設置服務器,然後通過filezilla進行連接? – 2012-04-01 16:43:18