我試圖上傳一個使用codeigniter的文件,無論我嘗試了什麼,我都會收到錯誤消息,說明我實際上沒有選擇文件。Codeigniter'您沒有選擇要上傳的文件。'
我的控制器看起來像這樣
public function editHeader()
{
$this->require_auth();
$config['upload_path'] = './files/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '1000KB';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if (! $this->upload->do_upload('userfile'))
{
$error = array('error' => $this->upload->display_errors());
var_dump($error);
}
else
{
$data = array('upload_data' => $this->upload->data());
echo('yeah!');
}
}
和我的HTML僅僅是一個笨形式
<?foreach($header as $row) :?>
<?=form_open_multipart('admin/editHeader');?>
<input class="waitForLoad fadeInDown" type="file" name="userfile" />
<input type="submit" name="submit" value="Change" class="btn btn-success pull-right" />
</form>
<?endforeach;?>
我已經嘗試了正常的解決方案,如加大了max_size
以及把上傳名稱do_upload函數,但似乎沒有任何工作,我即將把我的頭髮拉出來。任何幫助表示讚賞!
即使我沒有上傳多個文件?這實際上並沒有工作......它仍然給我同樣的錯誤信息 – zazvorniki 2014-10-05 23:54:17
@zazvorniki Yup。多部分與文件數量無關,並且根本無需上傳任何文件。從文檔(https://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html):'默認情況下,上傳例程期望文件來自稱爲userfile的表單字段,並且表單必須是「 multipart type' – 2014-10-06 00:08:05
奇怪的是,它仍然無法正常工作,您是否在$ _FILES中看到它? – 2014-10-06 00:09:51