2016-02-05 33 views
0
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!"; 
    } 
} 

“我已经尝试了一些教程,使这项工作,但似乎没有为这个工作”

+0

检查你的表单enctype属性是否设置。 http://www.w3schools.com/tags/att_form_enctype.asp – Sundar

+0

<?php echo form_open_multipart((base_url())。'admin/do_upload');?>

<?php echo form_close(); ?> 我已经检查过,这里是我的表格 – John

+0

的代码,你有没有失败的消息,然后试试这个print_r($ this-> upload-> display_errors());您也可以将文件上传字段名称作为do_upoad('userfile')方法中的参数传递。示例userfile是表单字段名称 – Sundar

回答

0

这可能是文件权限问题“上传”目录。设置适当的可写入权限来上传文件夹。

0
'upload_path' => $image_path, 
'allowed_types' => "gif|jpg|png|jpeg", 
'overwrite' => TRUE, 
'max_size' => "2048000", 
'max_height' => "1000", 
'max_width' => "2000" 

试试这个。

+0

请提供更多信息,说明;) – Soren