我看到CI文檔來創建一個圖片上傳。 這裏是我Controller
:如何在codeigniter中創建文件上傳器?
<?php
class Upload extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
}
function index()
{
$this->load->view('upload_form', array('error' => ' '));
}
function do_upload()
{
$this->load->helper(array('form', 'url'));
$this->load->helper('url');
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '0';
$config['max_width'] = '0';
$config['max_height'] = '0';
$this->load->library('upload', $config);
if (! $this->upload->do_upload())
{
echo $this->upload->display_error();
return FALSE;
}
else
{
$data = $this->upload->data();
return TRUE;
}
}
}
,這裏是我的View
<html>
<head>
<title>Upload Form</title>
</head>
<body>
<form action="upload/do_upload" method="post" accept-charset="utf-8" enctype="multipart/form-data">
<input type="file" name="userfile" size="20" />
<br /><br />
<input type="submit" value="upload" />
</form>
</body>
</html>
但是當我上傳的圖像不上傳並$this->upload->display_error()
顯示什麼(我上傳的文件夾這是在我的詞根文件夾也有777 permision和我使用WAMP)
我,你說什麼,但什麼都沒有改變 –
什麼你的錯誤,現在呢? print_r返回什麼? –
我評論了我所有的do_upload,並且只在我的函數中使用了print_r,它給了我Array([userfile] => Array([name] => chest.jpg [type] => image/jpeg [tmp_name] => C:\ wamp \ tmp \ php7295.tmp [error] => 0 [size] => 2085))但是當我取消註釋我的代碼時,它會再次返回upload_form並且什麼也沒有顯示 –