没有在codeigniter上传的图片

时间:2012-04-01 15:49:10

标签: php codeigniter

我已经用这个打了一个半小时,但是找不到问题。我正在使用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>   

在我选择无图片或选择图片之后,它给了我带有detials的var_dump -

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)

可能是什么问题?

1 个答案:

答案 0 :(得分:0)

$config['upload_path'] = './images/pictures/';确保您编写的路径正确并且具有正确的777权限以将文件写入。

另外,正如Kristian所写,你正在进行两次$this->upload->do_upload();上传部分。

要检查错误,您可以执行以下操作:

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