PHP多个文件上传 [英] PHP multiple file uploads

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

问题描述

我的截止日期非常紧迫,需要将文件上传脚本与我编写的管理面板集成在一起.

I'm on a very tight deadline and need to get a file upload script integrated with an admin panel I wrote.

基本上,用户需要能够上传多个图像,然后可以使用PHP处理这些图像.我可以使用多个input标记,但是如果他们要上传10张图像,这将是一个巨大的麻烦(这是正常现象).

Basically the user needs to be able to upload multiple images that I can then process with PHP. I could use multiple input tags but if they want to upload 10 images it will be a huge hassle (this would be the norm).

这里的主要问题是我不了解Javascript,Java或Flash,并且用户将需要使用Internet Explorer< 10,因此无法使用HTML5.我了解PHP,MYSQL,HTML,CSS,但对客户端没有帮助.

The main problem here is that I don't know Javascript, Java or Flash and users will need to use Internet Explorer < 10 so HTML5 can't be used. I have knowledge of PHP, MYSQL, HTML, CSS, but it's not helping with the clientside.

我研究了许多解决方案,并花费了很多小时试图自己寻找解决方案.我需要一些可以与我目前的知识相结合的东西,我没有时间学习Javascript.这就是为什么我在集成完整的成熟系统(例如plupload,SWFupload和uploadify)时遇到很多麻烦的原因.

I've looked at many solutions and spent far to many hours trying to find a solution myself. I need something that I can integrate with my current knowledge, I don't have time to learn Javascript. This is why I am having so much trouble trying to integrate fully fledged systems such as plupload, SWFupload and uploadify.

我尝试了一个多小时才能使uploadify正常工作,但效果并不理想.

I tried for over an hours to get uploadify to work, but it just isn't playing nice.

如果有人有一个简单的解决方案,请告诉我.我只希望能够使用一个input标记上传多个文件.没有调整大小,没有闪存接口,因为这一切将由服务器使用我的脚本来处理.用户必须能够一次选择多个图像.

If anyone has a simple solution please let me know. I simply want to be able to upload multiple files with one input tag. No resizing, no flash interface as this will all be handled by the server using my script. The user must be able to select multiple images at once though.

推荐答案

可以选择多个文件,然后使用
<input type='file' name='file[]' multiple>
用于上传的示例php脚本:

Multiple files can be selected and then uploaded using the
<input type='file' name='file[]' multiple>
The sample php script that does the uploading:

<html>
<title>Upload</title>
<?php
    session_start();
    $target=$_POST['directory'];
        if($target[strlen($target)-1]!='/')
                $target=$target.'/';
            $count=0;
            foreach ($_FILES['file']['name'] as $filename) 
            {
                $temp=$target;
                $tmp=$_FILES['file']['tmp_name'][$count];
                $count=$count + 1;
                $temp=$temp.basename($filename);
                move_uploaded_file($tmp,$temp);
                $temp='';
                $tmp='';
            }
    header("location:../../views/upload.php");
?>
</html>

所选文件以数组形式接收

The selected files are received as an array with

$_FILES['file']['name'][0]存储第一个文件的名称.
$_FILES['file']['name'][1]存储第二个文件的名称.
等等.

$_FILES['file']['name'][0] storing the name of first file.
$_FILES['file']['name'][1] storing the name of second file.
and so on.

在php中上传多个文件
上传教程

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

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