我想在我的網站上使用codeigniter的上傳庫添加文件上傳功能。codeigniter do_upload不工作
這裏是我的視圖文件(Display.php的):
<html>
<body>
<form method="post" action="" enctype="multipart/form-data">
<input type="file" name="filename" />
<input type="submit" name="submit" id="submit" value="submit"/>
</form>
</body>
</html>
和這裏的控制器:
public function testupload()
{
if (! empty($_FILES))
{
echo 'start upload';
$config['upload_path'] = './assets/img/tempfile/';
$this->load->library('upload');
$this->upload->initialize($config);
if (! $this->upload->do_upload('filename'))
{
echo 'error!';
}
else
{
echo 'success!';
}
echo 'end upload';
}
$this->load->view('display', $this->data);
}
但代碼看起來$this->upload->initialize($config);
之後停止該文件沒有上傳,並有根本沒有消息。只有'start upload'
消息出現;不出現echo 'success'
,echo 'error'
和echo 'end upload'
。
這是爲什麼?誰能幫我??
使用'$ this-> upload-> display_errors()'調試錯誤 –
啓用調試模式。 'ini_set('display_errors','1'); error_reporting(E_ALL);'並打印這個以及'$ this-> upload-> display_errors()'; – Naga
nope。沒有任何工作。如果放在'$ this-> upload-> do_upload('文件名')之後,甚至沒有簡單的'echo'blabla';';我嘗試了@Naga的建議,但仍然沒有任何結果。 – dapidmini