function do_upload(){//This is my controller//
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['overwrite'] = true;
//$config['max_size'] = '100';
//$config['max_width'] = '1024';
//$config['max_height'] = '768';
$this->load->library('upload');
$this->upload->initialize($config);
$this->upload->do_upload();
if (!$this->upload->do_upload()){//I also found out that this is the part that is not working
echo "failed!";
}
else{
$this->upload->data();
echo "success!";
}
}
「我已經嘗試了一些教程,使這項工作,但似乎沒有爲這個工作」
檢查你的表單enctype屬性是否設置。 http://www.w3schools.com/tags/att_form_enctype.asp – Sundar
<?php echo form_open_multipart((base_url())。'admin/do_upload');?>
<?php echo form_close(); ?> 我已經檢查過,這裏是我的表格 – John的代碼,你有沒有失敗的消息,然後試試這個print_r($ this-> upload-> display_errors());您也可以將文件上傳字段名稱作爲do_upoad('userfile')方法中的參數傳遞。示例userfile是表單字段名稱 – Sundar