Php Simple File Image batch upload program code. The batch upload method is also simple. you only need to add a namepictures [] array to the form, and then use foreach ($ _ FILES [pictures] [error] as $ key $ error) it is also easy to determine the batch upload method for arrays cyclically. we only need to add a name = \ "pictures [] \" array to form, then use foreach ($ _ FILES [\ "pictures \"] [\ "error \"] as $ key => $ error) to cyclically judge the array, and then use move_uploaded_file ($ tmp_name, $ uploadfile); implements file upload.
Html code
The code is as follows: |
|
Upload picture more once |
Php processing code
The code is as follows: |
|
If ($ _ POST ['upload'] = 'send '){ $ Dest_folder = "picture /"; If (! File_exists ($ dest_folder )){ Mkdir ($ dest_folder ); } Foreach ($ _ FILES ["pictures"] ["error"] as $ key => $ error ){ If ($ error = UPLOAD_ERR_ OK ){ $ Tmp_name = $ _ FILES ["pictures"] ["tmp_name"] [$ key]; $ Name = $ _ FILES ["pictures"] ["name"] [$ key]; $ Uploadfile = $ dest_folder. $ name; Move_uploaded_file ($ tmp_name, $ uploadfile ); } } } ?> |
The method is quite simple. we just changed the single file upload to multi-file upload, the others are changed to only two places. one is to change the form name to the php array form. The other is to use foreach to upload files to traverse the array.
Explain "pictures [] \" array, and then use foreach ($ _ FILES [\ "pictures \"] [\ "error \"] as $ key => $ error) array loop judgment...