CodeIgniter上传文件没有文件

时间:2014-11-29 14:46:42

标签: php codeigniter

好的尝试上传文件数小时但我收到错误,

You did not select a file to upload.

我的代码在CI中

 $this->config =  array(
                  'upload_path'     => dirname($_SERVER["SCRIPT_FILENAME"])."/uploads/",
                  'upload_url'      => base_url()."uploads/",
                  'allowed_types'   => "gif|jpg|png|jpeg|pdf|doc|xml",
                  'overwrite'       => TRUE,
                  'max_size'        => "1000KB",
                  'max_height'      => "768",
                  'max_width'       => "1024"  
                );

             $this->load->library('upload', $this->config);
            if($this->upload->do_upload('logo'))
            {
                echo "file upload success";
            }
            else
            {
               echo $this->upload->display_errors();
            }

在视图中我有

<input type="file" name="logo"/>

当我print_r $ _POST我得到

Array ( [name_srpski] => tyre [name_english] => Client nametre [logo] => cipele-plava_1.jpg )

错误可能在哪里非常重要

2 个答案:

答案 0 :(得分:0)

在config中尝试以下内容:

'upload_path'     => FCPATH . "/uploads/", // or use "./uploads/" instead
'max_size'        => "1000", // remove the kb from the string. it requires only the number

答案 1 :(得分:-1)

尝试将$this->load->library('upload', $this->config);更改为

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

表单类型也应该是多部分

<form method="post" action="some_action" enctype="multipart/form-data" />