PHP多个文件阵 [英] PHP Multiple File Array

查看:128
本文介绍了PHP多个文件阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code这工作和上传,但它会遍历数组不是周期的每一个文件,只要第一个文件上传

I have the following code which works and uploads but it will not cycle through the array to upload every file, just the first file.

<form method="post" enctype="multipart/form-data" action="http://<?php echo $pageURL;?>">   
<input class="new" multiple="multiple" name="documents[]" type="file" />
<input class="new" multiple="multiple" name="documents[]" type="file" />
<input type="submit" class="button" name="addMaterials" value="Add" />

<?php

    foreach($_FILES['documents']['tmp_name'] as $key => $tmp_name)
        {
            $file_name = $key.$_FILES['documents']['name'][$key];
            $file_size =$_FILES['documents']['size'][$key];
            $file_tmp =$_FILES['documents']['tmp_name'][$key];
            $file_type=$_FILES['documents']['type'][$key];  
            move_uploaded_file($file_tmp,"files/".time().$file_name);
        }
?>

我需要它循环我的文档[]数组文件

I need it to cycle through my documents[] file array.

示例的print_r()文件数组:

Array ( 
    [name] => Array ( [0] => AcroRd32.exe ) 
    [type] => Array ( [0] => application/x-msdownload ) 
    [tmp_name] => Array ( [0] => C:\xampp\tmp\phpE8BD.tmp ) 
    [error] => Array ( [0] => 0 ) 
    [size] => Array ( [0] => 1343112 ) 
    )

任何帮助AP preciated。

Any help appreciated.

推荐答案

您可以用我的更新code和按我的演示是对多文件上传的工作完美

you can use my updated code and as per my demo it is working perfect for multiple file upload

 <?php
if(isset($_FILES['documents'])){

foreach($_FILES['documents']['tmp_name'] as $key => $tmp_name)
{
    $file_name = $key.$_FILES['documents']['name'][$key];
    $file_size =$_FILES['documents']['size'][$key];
    $file_tmp =$_FILES['documents']['tmp_name'][$key];
    $file_type=$_FILES['documents']['type'][$key];  
    move_uploaded_file($file_tmp,"galleries/".time().$file_name);
}
}else{
echo "<form enctype='multipart/form-data' action='test1.php' method='POST'>";
 echo "File:<input name='documents[]' multiple='multiple' type='file'/><input type='submit' value='Upload'/>";

 echo "</form>";
}
?>

这篇关于PHP多个文件阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆