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...