Codeigniter: Image Upload

北城余情 提交于 2019-11-30 15:58:21

First of all don't get the do_upload() for granted, you have to validate the upload:

if ( ! $this->upload->do_upload('file_1'))
{
    // something went wrong, display errors
}   
else
{
    // everything is fine
}

Also, most likely it's your upload_path, check the document I linked to:

//You'll need a destination folder for your uploaded images. Create a folder at the root of your CodeIgniter installation called uploads and set its file permissions to 777.  
$config['upload_path'] = './uploads/';

So you may need to change your setting to something like:

$config['upload_path'] = './assets/uploads/avatars/';

codeigniter expects your file input to be named userfile, unless you specify in your code like this,

$field_name = "some_field_name";
$this->upload->do_upload($field_name)

I am not sure what the problem is. But May be the below links could help you.

Upload file bug in codeigniter

Also you can initialize the config to set preferences.

$this->upload->initialize($config);

File Uploading class in codeigniter

Make sure the name of the input file is set to "userfile" because the upload function expects the files coming from an input field whose name is set to "userfile"

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!