Php uploads images in batches and puts the image name into the database _ PHP Tutorial

Source: Internet
Author: User
Tags glob
Php uploads images in batches and puts the image names in the database. A few days ago, I was working on this function. more than eight hundred members were generated by more than eight hundred systems. I uploaded images to more than system members, and then put the image names in the database. Step 1: In the first few days of work, we should make such a function, with more than eight hundred members generated by the system; upload images to more than eight hundred system members; then put the image name into the database.

Step 1:

The first step is to upload the image to the corresponding image directory and directly use the existing Upload class in the framework:

 Set_ext (array ('Zip '); $ path = 'directory name'; if (! Io: mkdir ($ path) // Create directory {throw new Exception ("unable to create file Upload Directory: $ path ");} $ upload-> set_path ($ path); if (! $ Upload-> is_allow_ext ($ _ FILES ['files '] ['name']) {$ this-> show_message ('Zip-format data required', '0 ', NULL, TRUE) ;}$ result = $ upload-> save ($ _ FILES ['Files']); $ archive = new Archive_Zip (); $ archive-> set_target ($ path)-> decompress ($ result ['file']); unlink ($ result ['file']); // delete the used zip; $ this-> show_message ('Imported successfully', '1', array ('text' => 'Return to import page ', 'href '=>' *** jump link address *** '), TRUE);} catch (Exception $ e) {$ this-> show_me Ssage ('image import failed', '0', NULL, TRUE) ;}}?>

Step 2:

After the image is uploaded, retrieve the image names of all system members in the directory, and traverse the image. Think about it and you don't have to worry about it. php comes with the glob function ();

The glob () function returns a file name or directory that matches the specified mode.

This function returns an array containing matching files/directories. If an error occurs, false is returned.


 

In the loop process, because I only want to get the image name, I replaced the previous directory with null.



Step 3:

After listing all the images, you should insert the image file name into the database.

Write a loop.

First, SELECT ........ Find out the system members and calculate the number of system members,

 Execute ()-> as_array ();?>


Then recycle and insert it into the database:

 $ Files [$ I],); DB: update ('Member table')-> set ($ data)-> where ('system member ID', '= ', $ member [$ I] ['system member id'])-> execute ();}?>


OK. That's it.

More than eight hundred members generated by the system; upload images to these eight hundred system members; and then put the image names in the database. Step 1: step...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.