\r\n \r\n \r\n <\/td>\r\n <\/tr>\r\n <\/tbody>\r\n <\/table>\r\n <\/form>\r\n<\/body>\r\n<\/html>\r\n\";\r\n }\r\n }\r\n}\r\n?><\/pre> The output result is as follows: <\/p>\n <\/p>\n
Summary: <\/strong><\/p> Regarding the file system, we first introduced the basic operations on files, then learned the basic operations on directories, then we learned advanced file processing technology, and finally learned PHP's file upload technology. The file system is an indispensable part of developing a website. I hope everyone can understand the key knowledge points of the file system and master common functions. See you in the next topic! <\/p>"}
Home
Backend Development
PHP Tutorial
PHP file upload-detailed explanation of sample code for multiple file uploads
PHP file upload-detailed explanation of sample code for multiple file uploads
Apr 18, 2017 am 11:34 AM
PHP file upload—detailed explanation of sample code for multiple file uploads
PHP supports uploading multiple files at the same time and automatically names their information in the form of an array , it is actually very simple to implement such a function. You only need to use the file upload field in the HTML form and the array submission syntax of multi-select boxes and check boxes.
Then the function of uploading files was introduced in the previous article "PHP File Upload-move_uploaded_file() Function". It only introduced the use of this function and single file upload. This chapter will Introducing how to implement multiple file uploads!
It was also introduced in the previous article "PHP Comprehensive Use of Array Functions - Implementing Multi-File Upload". In PHP, when the form request submitted by the browser client contains When uploading a file, PHP will temporarily store the uploaded file in the temporary directory, and then store the uploaded file information in the global variable $_FLIES, so we only need to obtain the uploaded file information through the $_FILES array, and then process it Just perform the corresponding processing operations!
The example below has 4 file upload fields. The name of the file field is u_file[]. The file information uploaded after submission will be saved in $_FILES['u_file']. The generated file is mostly an array. Read Get the array information and upload the file. The specific example code is as follows: <html>
<body>
<!--上傳文件表單-->
<form method="post" action="" enctype="multipart/form-data">
<table id="up_table" border="1" bgcolor="f0f0f0">
<tbody id="auto">
<tr id="auto">
<td>上傳文件</td>
<td><input type="file" name="u_file[]"></td>
</tr>
<tr>
<td>上傳文件</td>
<td><input name="u_file[]" type="file"></td>
</tr>
<tr>
<td colspan="4">
<input type="submit" value="上傳" >
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
<?php
header("Content-Type:text/html; charset=utf-8");
if(!empty($_FILES['u_file']['name'])){ //判斷變量$_FILES是否為空
$file_name = $_FILES['u_file']['name']; //將上傳文件名另存為數(shù)組
$file_tmp_name = $_FILES['u_file']['name']; //將上傳文件的臨時文件名存為數(shù)組
for($i=0;$i<count($file_name);$i++){ //循環(huán)上傳文件
if($file_name[$i]!=""){ //判斷上傳文件名是否為空
move_uploaded_file($file_tmp_name[$i],$i.$file_name[$i]);
echo "文件".$file_name[$i]."上傳成功,更名為".$i.$file_name[$i]."<br>";
}
}
}
?> The output result is as follows:

Summary: Regarding the file system, we first introduced the basic operations on files, then learned the basic operations on directories, then we learned advanced file processing technology, and finally learned PHP's file upload technology. The file system is an indispensable part of developing a website. I hope everyone can understand the key knowledge points of the file system and master common functions. See you in the next topic! The above is the detailed content of PHP file upload-detailed explanation of sample code for multiple file uploads. For more information, please follow other related articles on the PHP Chinese website!
Statement of this Website
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
Why We Comment: A PHP Guide
Jul 15, 2025 am 02:48 AM
PHPhasthreecommentstyles://,#forsingle-lineand/.../formulti-line.Usecommentstoexplainwhycodeexists,notwhatitdoes.MarkTODO/FIXMEitemsanddisablecodetemporarilyduringdebugging.Avoidover-commentingsimplelogic.Writeconcise,grammaticallycorrectcommentsandu
How to Install PHP on Windows
Jul 15, 2025 am 02:46 AM
The key steps to install PHP on Windows include: 1. Download the appropriate PHP version and decompress it. It is recommended to use ThreadSafe version with Apache or NonThreadSafe version with Nginx; 2. Configure the php.ini file and rename php.ini-development or php.ini-production to php.ini; 3. Add the PHP path to the system environment variable Path for command line use; 4. Test whether PHP is installed successfully, execute php-v through the command line and run the built-in server to test the parsing capabilities; 5. If you use Apache, you need to configure P in httpd.conf
PHP Syntax: The Basics
Jul 15, 2025 am 02:46 AM
The basic syntax of PHP includes four key points: 1. The PHP tag must be ended, and the use of complete tags is recommended; 2. Echo and print are commonly used for output content, among which echo supports multiple parameters and is more efficient; 3. The annotation methods include //, # and //, to improve code readability; 4. Each statement must end with a semicolon, and spaces and line breaks do not affect execution but affect readability. Mastering these basic rules can help write clear and stable PHP code.
PHP 8 Installation Guide
Jul 16, 2025 am 03:41 AM
The steps to install PHP8 on Ubuntu are: 1. Update the software package list; 2. Install PHP8 and basic components; 3. Check the version to confirm that the installation is successful; 4. Install additional modules as needed. Windows users can download and decompress the ZIP package, then modify the configuration file, enable extensions, and add the path to environment variables. macOS users recommend using Homebrew to install, and perform steps such as adding tap, installing PHP8, setting the default version and verifying the version. Although the installation methods are different under different systems, the process is clear, so you can choose the right method according to the purpose.
Your First PHP Script: A Practical Introduction
Jul 16, 2025 am 03:42 AM
How to start writing your first PHP script? First, set up the local development environment, install XAMPP/MAMP/LAMP, and use a text editor to understand the server's running principle. Secondly, create a file called hello.php, enter the basic code and run the test. Third, learn to use PHP and HTML to achieve dynamic content output. Finally, pay attention to common errors such as missing semicolons, citation issues, and file extension errors, and enable error reports for debugging.
What is PHP and What is it Used For?
Jul 16, 2025 am 03:45 AM
PHPisaserver-sidescriptinglanguageusedforwebdevelopment,especiallyfordynamicwebsitesandCMSplatformslikeWordPress.Itrunsontheserver,processesdata,interactswithdatabases,andsendsHTMLtobrowsers.Commonusesincludeuserauthentication,e-commerceplatforms,for
python if else example
Jul 15, 2025 am 02:55 AM
The key to writing Python's ifelse statements is to understand the logical structure and details. 1. The infrastructure is to execute a piece of code if conditions are established, otherwise the else part is executed, else is optional; 2. Multi-condition judgment is implemented with elif, and it is executed sequentially and stopped once it is met; 3. Nested if is used for further subdivision judgment, it is recommended not to exceed two layers; 4. A ternary expression can be used to replace simple ifelse in a simple scenario. Only by paying attention to indentation, conditional order and logical integrity can we write clear and stable judgment codes.
How Do You Handle File Operations (Reading/Writing) in PHP?
Jul 16, 2025 am 03:48 AM
TohandlefileoperationsinPHP,useappropriatefunctionsandmodes.1.Toreadafile,usefile_get_contents()forsmallfilesorfgets()inaloopforline-by-lineprocessing.2.Towritetoafile,usefile_put_contents()forsimplewritesorappendingwiththeFILE_APPENDflag,orfwrite()w
See all articles
|