我與此戰鬥已經1個半小時,但無法找到問題。我使用笨和上傳功能,但它總是失敗上傳 -沒有圖片上傳在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>
後,我選擇沒有圖像,或者如果我選擇圖片,它給我var_dump與detials -
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)
可能是什麼問題?
它是如何失敗?怎麼了?你有錯誤嗎? – kba 2012-04-01 15:55:57
沒有錯誤,它只是加載var_dump ...檢查控制器,它說如果上傳失敗,然後加載var_dump,否則重定向。 ;/ – 2012-04-01 16:04:18
你正在做'$ this-> upload-> do_upload()'兩次。 – kba 2012-04-01 16:12:52