The method and steps of uploading pictures successfully in CodeIgniter
This article introduces the relevant knowledge of "successful method steps of uploading pictures in CodeIgniter". In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!
The copy code is as follows:
/* Note, here is userfile,$this->upload->do_upload(), here do_upload default upload file form name is userfile;
Do_upload($filename) can also be used, where $filename must match the string in form_upload().
I am here Fan confused, finally read the manual to understand, I hope you pay attention to Oh!
*/
Controller Code:
function upload() {
$config['upload_path'] = './ uploads/';
The requested URL/uploads/index.php was not found on this server.
"The upload path does not appear to be valid. ";
*/
$config['allowed_types'] = 'gif|jpg|png';
/* I try to upload other types of files, be sure to pay attention to the order here!
A problem was encountered while attempting to move the uploaded file to the final destination.
This error is generally uploaded file name can not be Chinese name, this is very depressed! Not resolved, we can use other methods, to change the file name can be resolved!
$config['allowed_types'] = 'zip| gz| png| gif| jpg';(correct)
$config['allowed_types'] = 'png| gif| jpg| zip| gz';(error)
*/
$config['max_size'] = '1024';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config ['file_name'] = time(); //file name does not use original name
$this->load->library('upload', $config);
if(!$ this->upload->do_upload()) {
echo $this->upload->display_errors();
}else{
$data ['upload_data']=$this->upload->data(); //some information about the file
$img=$data <$'upload_data']<$'file_name']; //get file name
echo $img. "
";
foreach($data['upload_data'] as $item => $value){
echo $item. ":".$ value. "
";
}
}
}
"How to upload pictures successfully in CodeIgniter" is introduced here. Thank you for reading it. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!