Home > php教程 > php手册 > body text

php 实现多文件上传程序代码

WBOY
Release: 2016-06-13 11:27:44
Original
985 people have browsed it

php文件上传与多文件上传其它没有多大的区别,多文件上传只是我们把表单名改成数组形式,而获取利用foreach遍历就可以实现多文件上传了,动态多文件上传只要在js加一个动态增加多文件上传框,同样在php处理时就遍历一下数组就成了。

最简单的实例如下

 代码如下 复制代码


Pictures:





       foreach ($_FILES["pictures"]["error"] as $key => $error) {
        if ($error == UPLOAD_ERR_OK) {
            $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
            $name = $_FILES["pictures"]["name"][$key];
            move_uploaded_file($tmp_name, "data/$name");
        }
}
?>

 

下面分享其它朋友的例子
例1

 代码如下 复制代码


//filename:multi_upload.php
if($ifupload)
{
$path=AddSlashes(dirname($PATH_TRANSLATED))."upload";
for($i=1;$i{
$files="afile".$i;
if(${$files}!="none")
{
if(copy(${$files},$path.${$files."_name"}))
{
}
}
}
print "You have uploaded files successfully
";
print "Return";
exit;
}
?>





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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template