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