Home > Backend Development > PHP Tutorial > PHP file upload function -- multiple file upload

PHP file upload function -- multiple file upload

WBOY
Release: 2016-08-08 09:25:35
Original
842 people have browsed it

This section mainly introduces the multi-file upload function of PHP upload files.
As long as you name the file upload tag in the form in the form of an array, you can upload multiple files at the same time.
Let’s take a look at an example:
------------------------------------------------- ----------------------------


                                                                                                                                  ;td>Upload files:
                                                                                                    Upload file:
                                                                                                                                                                                        name="upload_file[]" type="file" size="50" />
                                                                                                                                                               ="submit" value="Upload"/>
; $file_name){
            $info = "";               $info = $file_name. ": File size exceeded Server limit ";
                                                                                                                                                                                                                                                                                            case UPLOAD_ERR_PARTIAL:
                                                                                                                                                                                                                                                   Part of the file ";
                                   break; case UPLOAD_ERR_NO_TMP_DIR:
                   $info = $file_name. ": Temporary folder not found";
                                          break; UPLOAD_ERR_OK:
$upload_dir = './'.iconv("UTF-8","gb2312",$file_name);
                                                                                                   }else{
                                                                                                                                        else{
                               $info = $                                                                                                                                                                                                               $info =                                                 A}
Break;
}
Return $ Info;
}
if (isset ($ _ Post ['Submit'])) {
$ info = ''; '] [ 'name']);
for($i=0; $i<$count; ++$i){
if($_FILES['upload_file']['name'][$i] == "")
                                                                                                                                                                                                                              $info $i],
                       $_FILES[' upload_file']['name'][$i]
               ); -------------------------------------------------- ---------------
The code execution results are as follows:


Note:
1. , name="upload_file[]" must be named in array form, otherwise an error will occur: "Uninitialized string offset: 0", this sentence means that your array key value is out of bounds
2. $_FILES In ['upload_file']['name'][$i], upload_file is the name of the upload file marker in the form. When uploading multiple files, the third-dimensional subscript of the array $_FILES will automatically be numbered sequentially from 0.
The above has introduced the PHP file upload function - multi-file upload, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.


Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template