After images are uploaded in batches, how do I insert paths to the database together with other fields?

Source: Internet
Author: User
After images are uploaded in batches, how do I insert paths to the database together with other fields? Upload database images




Batch upload of images



Select the file to Upload


$ Destination_folder = "picture /";

If (! File_exists ($ destination_folder ))
{
Mkdir ($ destination_folder );
}

Foreach ($ _ FILES ["u_file"] ["error"] as $ key => $ error ){
If ($ error = UPLOAD_ERR_ OK ){
$ Tmp_name = $ _ FILES ["u_file"] ["tmp_name"] [$ key];
$ Name = $ _ FILES ["u_file"] ["name"] [$ key];
$ Uploadfile = $ destination_folder.time (). $ name;
Move_uploaded_file ($ tmp_name, $ uploadfile );
Echo 'file '. $ name.' uploaded successfully. image path: '. $ uploadfile .'
';

}
}
?>




The red part indicates the path of the three images that are successfully uploaded.
Then, in the image description, enter the description text. how can I submit the path of the three images together with the input image description to the database?
For example, if the database is picture, the corresponding fields are picid, p_explain (image description), s_pic (small image path), m_pic (), and B _pic (large Image path)


Reply to discussion (solution)

...........
Echo 'file '. $ name.' uploaded successfully. image path: '. $ uploadfile .'
';
$ Arr [] = $ uploadfile;
}
$ SQL = "insert into picture values ('', '$ _ POST ['wd'] ',' $ arr [0] ',' $ arr [1] ', '$ arr [2]') ";
Mysql_query ($ SQL );

LZ do you want to insert N records at the same time?

insert into tableName(AA, BB, CC) values(1, 1, 1),(2, 2, 2);

The SQL statement can be spliced during the foreach loop Upload and executed after successful completion.




Batch upload of images



Select the file to Upload


$ Destination_folder = "picture /";

If (! File_exists ($ destination_folder ))
{
Mkdir ($ destination_folder );
}

Foreach ($ _ FILES ["u_file"] ["error"] as $ key => $ error ){
If ($ error = UPLOAD_ERR_ OK ){
$ Tmp_name = $ _ FILES ["u_file"] ["tmp_name"] [$ key];
$ Name = $ _ FILES ["u_file"] ["name"] [$ key];
$ Uploadfile = $ destination_folder.time (). $ name;
Move_uploaded_file ($ tmp_name, $ uploadfile );
Echo 'file '. $ name.' uploaded successfully. image path: '. $ uploadfile .'
';

}
}
?>




The red part indicates the path of the three images that are successfully uploaded.
Then, in the image description, enter the description text. how can I submit the path of the three images together with the input image description to the database?
For example, if the database is picture, the corresponding fields are picid, p_explain (image description), s_pic (small image path), m_pic (), and B _pic (large Image path)

...........
Echo 'file '. $ name.' uploaded successfully. image path: '. $ uploadfile .'
';
$ Arr [] = $ uploadfile;
}
$ SQL = "insert into picture values ('', '$ _ POST ['wd'] ',' $ arr [0] ',' $ arr [1] ', '$ arr [2]') ";
Mysql_query ($ SQL );

Is there a problem with the array obtained by $ arr?
Array ([0] => picture/13703303631.jpg)
Array ([0] => picture/13703303631.jpg [1] => picture/13703303632.jpg)
Array ([0] => picture/13703303631.jpg [1] => picture/13703303632.jpg [2] => picture/13703303633.jpg)

No problem. you printed it in foreach, of course, that result. Please take a closer look at the replies in #1.

No problem. you printed it in foreach, of course, that result. Please take a closer look at the replies in #1.

Thank you for your answers. the function has been implemented.

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.