2012-04-01 81 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