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.