In recent days are doing a small CMS, with the picture upload, want to facilitate CodeIgniter upload class to achieve, but there are many problems in testing, I have to pay attention to the place to share!
Copy CodeThe code is as follows:
/* Note, here is UserFile, $this->upload->do_upload (), here do_upload the default File upload table sole name for userfile;
Of course, you can also use Do_upload ($filename), where the $filename must be consistent with the string inside the Form_upload ().
I am here fan confused, finally read the handbook to understand, I hope you pay attention to Oh!
*/
Controller code:
function upload () {
$config [' upload_path '] = './uploads/';
/* Here uploads is relative to the index.php, that is, the entry file, this must not be mistaken Oh!
Otherwise you will get an error "The upload path does not appear to be valid.";
*/
$config [' allowed_types '] = ' gif|jpg|png ';
/* I try to upload other types of files, here must pay attention to the order!
A problem is encountered while attempting to move the uploaded file to the final destination.
This error is generally uploaded file filename can not be Chinese name, this is very depressed! Not resolved, you can use other methods, re-change the file name can be solved!
$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 (); The file name does not use the 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. "
";
}
}
}
http://www.bkjia.com/PHPjc/328181.html www.bkjia.com true http://www.bkjia.com/PHPjc/328181.html techarticle In recent days are doing a small CMS, with the picture upload, want to facilitate CodeIgniter upload class to achieve, but there are many problems in the test, I have to pay attention to the place to share a bit! Copy ...