PHP File upload multi-file upload implementation ideas, _php tutorial

Source: Internet
Author: User

PHP File upload of the implementation of multi-file upload ideas,


Two scenarios for uploading multiple files

① using multiple name values

a. Click the data format you received after submitting

Array ([file1] = = Array ([name] = 8.png[type] = Image/png[tmp_name] = G:\wamp\tmp\php737.tmp[error] + 0 [Size] = [File2] = Array ([name] = 28.png[type] = Image/png[tmp_name] = g:\wamp\tmp\php738.tmp[ ERROR] [0[size] = 6244) [File3] = = Array ([name] = 54a296f8n6787b34c.png[type] = Image/png[tmp_name] =& Gt G:\wamp\tmp\php739.tmp[error] = 0[size] = 3143) [File4] = = Array ([name] = = 54c0573dncb4db6f7.jpg[type] = > Image/jpeg[tmp_name] [g:\wamp\tmp\php788.tmp[error] = 0[size] + 5404))

As you can see from this format, each file corresponds to an array of cells

So use foreach to iterate through the array and make a file upload function call to each array cell

B. Click on the post-commit action

① receiving uploaded file information

$file = $_files;

② Introducing the Upload function

Include ('./functions.php ');

③ Setting File Save path

$path = './uploads/'; This directory needs to be manually created

④ Call File Upload function

foreach ($file as $v) {$info = UploadFile ($v, $path); ⑤ determines the upload status if ($info [' isOK ']) {echo ' upload succeeded '. $info [' message '];} else {echo ' Upload failed '. $info [' message '];}}

---------------------------------------------------------------

② using a single name value

A. First wording

B. Second wording

C. After clicking Submit, the received data format

Array ([userpic] = = Array ([name] = = Array ([0] = 8.png[1] = 9b2d7581fba543ec9bcf95e91018915a.gif[2] = 12.jpg) [Type] = = Array ([0] = image/png[1] = image/gif[2] = image/jpeg) [Tmp_name] = = Array ([0] = = g:\w AMP\TMP\PHP85E5.TMP[1] = g:\wamp\tmp\php85e6.tmp[2] = G:\wamp\tmp\php8635.tmp) [ERROR] = = Array ([0] = 0[ 1] = 0[2] + 0) [size] = = Array ([0] = 200[1] = 16503[2] = 19443)))

As you can see from this format, the uploaded file information is saved separately into each subscript.
So the thing to do is to stitch up a complete file information, a one-dimensional array

Array ([name] = 54c0573dncb4db6f7.jpg[type] [image/jpeg[tmp_name] = g:\wamp\tmp\php788.tmp[error] = 0[ Size] = 5404)

So the operation is to traverse $_files[' file ' and then extract the information from each of the uploaded files.

D. Click on the post-commit action

① receiving uploaded file information

$file = $_files[' file '];

② Introducing the Upload function

Include ('./functions.php ');

③ Setting File Save path

$path = './uploads/'; This directory needs to be manually created

④ Call File Upload function

foreach ($file [' name '] as $key + = $value) {$data [' name '] = $file [' name '] [$key]; $data [' type '] = $file [' type '] [$key];$ data[' tmp_name ' = $file [' Tmp_name '] [$key]; $data [' error '] = $file [' ERROR '] [$key]; $data [' size '] = $file [' Size '] [$key] ; $info = UploadFile ($data, $path);

⑤ Determine upload status

if ($info [' isOK ']) {echo ' upload succeeded '. $info [' message '];} else {echo ' upload failed '. $info [' message '];}}

A. Traverse $file[' name '] just to get $key

B. Each time the traversal, remove the relative subscript of the file information, assigned to a new array of corresponding keys

such as the first time $key = 0;

$data [' name '] = $file [' name '][0]; The equivalent of removing the first file name $data[' type '] = $file [' type '][0]; The equivalent of removing the type of the first file

...

After the first traversal is complete

$data = Array ([name] = 54c0573dncb4db6f7.jpg[type] = Image/jpeg[tmp_name] = G:\wamp\tmp\php788.tmp[error] = > 0[size] = 5404);

This takes out all the information from the first file.

And then call the upload function for file upload processing

The second time elapsed $key=1, equivalent to getting the second upload file information

Articles you may be interested in:

    • Php5+utf8 Multi-File Upload class
    • PHP dynamic Multi-File upload
    • The latest PHP file upload model, support multi-file upload
    • How to deal with multi-file upload of common form in PHP
    • PHP multi-File Upload function implementation principle and code
    • PHP jquery Multi-File Upload simple example
    • PHP Multi-File upload implementation code
    • PHP multi-File upload download sample sharing
    • thinkphp Multi-File Upload implementation method
    • PHP Multi-File Upload class instance
    • PHP multi-File Upload instance
    • PHP for file upload and multi-file upload

http://www.bkjia.com/PHPjc/1096142.html www.bkjia.com true http://www.bkjia.com/PHPjc/1096142.html techarticle php File Upload multi-file upload implementation ideas, multi-file Upload two cases ① use multiple name value input type= "file" name= "file1" input type= "file" name= "file2" Input type= " Fi ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.