Home > Backend Development > PHP Tutorial > Share the entire process of successfully uploading images with CodeIgniter_PHP tutorial

Share the entire process of successfully uploading images with CodeIgniter_PHP tutorial

WBOY
Release: 2016-07-21 14:58:58
Original
977 people have browsed it

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!

Copy code The code is as follows:


Of course, you can also use do_upload($filename). The $filename here must be consistent with the string in form_upload().
I was confused here and finally understood it after reading the manual. I hope everyone pays attention!
*/

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

$ img = $ data ['upload_data']; /'file_name']; / /Get file name


echo $img."
";

Foreach ($ Data ['upload_data'] as $ item = & gt; $ value) {
echo $ item. ":". $ Value. "& Lt;"

         }

}

}


http://www.bkjia.com/PHPjc/328181.html

www.bkjia.com

true

http: //www.bkjia.com/PHPjc/328181.html

In the past few days, I have been working on a small CMS and used 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 should be paid attention to! Copy...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template