$error) to Circular judgment"/> $error) to Circular judgment">

Home >Backend Development >PHP Tutorial >PHP simple file and image batch upload program code_PHP tutorial

PHP simple file and image batch upload program code_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:13:401050browse

The batch upload method is also very simple. We only need to add a name="pictures[]" array to the form, and then use foreach ($_FILES["pictures"]["error"] as $key => $error ) Loop through the array and then use move_uploaded_file($tmp_name, $uploadfile); to upload the file.

html code

The code is as follows
 代码如下 复制代码

upload picture more once

 

Pictures:


 

 

 

Copy code

 代码如下 复制代码

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); 

      } 

?> 

upload picture more once

Pictures:



php processing code
The code is as follows Copy code
<🎜>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 multiple file upload. We only changed two other places. One is to change the form name to a php array format. The other is to use foreach to traverse the array where the files are uploaded. http://www.bkjia.com/PHPjc/629142.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/629142.htmlTechArticleThe batch upload method is also very simple. We only need to add a name="pictures[]" array to the form, and then Then use foreach ($_FILES["pictures"]["error"] as $key => $error) to loop through the array...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn