国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

php multiple file upload

Introduces the process of uploading a single file in PHP. But sometimes, for convenience, we need to meet the need to upload multiple files at the same time. The principle of multi-file upload is the same, but when processing data, the uploaded data needs to be specially processed.

<html> 
   <head> 
       <meta charset="utf-8" /> 
       <title>單文件上傳</title> 
   </head> 
   <body> 
       <form action="morefile.php" method="post" enctype="multipart/form-data"> 
        <input type="file" name="file[]"> 
        <input type="file" name="file[]"> 
        <input type="submit" value="上傳"> 
    </form> 
   </body> 
</html>

Here is a simple upload page, and the form submits two files at the same time. We can submit content through this page.

Note:

1.Input type="file" name="file[]"Compared with before, an extra square bracket is added after file

2.Write 2 or more input type="file" name="file[]"
We use $_FILES to receive file information, print and view the array:

<?php 
var_dump($_FILES); //打印$_FILES查看數(shù)組結構 
?>

The array structure is as follows

array (size=1)  
    'file' =>  
        array (size=5) 
    'name' =>  
        array (size=2) 
        //文件名 
        0 => string 'psu.jpg' (length=7) 
        1 => string 'qwe.jpg' (length=7) 
    //文件mime類型 
    'type' => array (size=2) 
            0 => string 'image/jpeg' (length=10) 
            1 => string 'image/jpeg' (length=10) 
    //緩存文件 
    'tmp_name' =>  
        array (size=2) 
            0 => string 'E:\wamp\tmp\phpF6D5.tmp' (length=23) 
            1 => string 'E:\wamp\tmp\phpF6F5.tmp' (length=23) 
    //文件錯誤信息 
    'error' =>  
        array (size=2) 
            0 => int 0 
            1 => int 0 
    //文件大小 
    'size' =>  
        array (size=2) 
        0 => int 225824     
        1 => int 151651

We can see that the two files are stored in an array, and the key names are the same as the uploaded single file. Therefore, we need to use a for() loop to retrieve the required data from the two files respectively.

The data of two files are saved in $_FILES at the same time. We need to use a simple loop to read the information of a single file and move the file to the location we want to put.

<?php
for ($i=0; $i < count($_FILE['file']['name']); $i++) {  

/* 
用is_uploaded_file()函數(shù)判斷是上傳文件 
并且沒有出現(xiàn)錯 
*/ 

   if(is_uploaded_file($_FILEs['file']['tmp_name'][$i]) && $_FILEs['file']['error'][$i] == 0){     
       if(move_uploaded_file($_FILEs['file']['tmp_name'][$i],'upload/'.$_FILE['file']['name'][$i])){
   //用move_uploaded_file()函數(shù)移動文件到指定的位置并使用文件原名 
   echo "上傳成功"; 

       }else{ 

           echo '上傳失敗'; 

       } 

   }else{ 

       echo '上傳失敗'; 

   } 

} 
?>

For the detailed judgment process, see single file upload. Only basic judgment is made here, and there is no reminder about the file size and format.
Please judge the file size and format by yourself according to the business and provide error reminders.

Continuing Learning
||
<?php var_dump($_FILES); //打印$_FILES查看數(shù)組結構 ?>
submitReset Code