I have been working on a small CMS in the past few days, and I am using it to upload images. I want to use CodeIgniter’s upload class to implement it, but there are many problems in the test. I will share my experience and what I need to pay attention to!
controller code:
function upload() { $config['upload_path'] = './uploads/'; The uploads are relative to Index.php, that is, the entry file, don't make a mistake! Otherwise, you will report an error. > $config['allowed_types'] = 'gif|jpg|png';
uploaded file to the final destination.
This error usually means that the file name of the uploaded file cannot be a Chinese name. This is very frustrating! It has not been solved yet. You can use other methods and rename the file to solve it!
$config['allowed_types'] = 'zip|gz|png|gif|jpg'; (Correct)
$config['allowed_types'] = 'png|gif|jpg|zip|gz'; (wrong)
*/
$config['max_size'] = '1024';
$config['max_width'] = '1024';
$config['file_name'] = time(); //Do not use the original name for the file name
$this->load->library('upload', $config);
if( !$this->upload->do_upload()) {
echo $this->upload->display_errors();
$ data ['upload_data'] = $ this- & gt; upload- & gt; data (); // Some information of the file
echo $img."
";
Foreach ($ Data ['upload_data'] as $ item = & gt; $ value) {
echo $ item. ":". $ Value. "& Lt;"
}
}
http://www.bkjia.com/PHPjc/328181.html
www.bkjia.com
http: //www.bkjia.com/PHPjc/328181.html