使用PHP / Javascript进行多文件上传,无闪存 [英] Multi file upload with PHP/Javascript and no flash

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

问题描述

我正在尝试制作一个允许同时上传多个文件的网页。我会将文件扩展名限制为最常见的图像,如JPG,JPEG,PNG和GIF。

I'm trying to make a webpage that allows the uploading of multiple files at the same times. I will limit the file extensions to the most common images like JPG, JPEG, PNG and GIF.

我已经对此进行了一些研究,无处不在我看起来是闪存这个然后闪现。

I've done some research on this and everywhere I look it's flash this and flash that.

我真的不想使用闪存。特别是Flash 10,它禁用了最常用的方法来启用多文件上传。

I don't want to use flash really. Especially with Flash 10, which disables the most common used method to enable multifile upload.

我正在寻找的是一种不断创建越来越多输入字段的方法,每个都有一个浏览按钮,然后在表单底部有一个最终上传按钮。使用Javascript创建新的输入字段真是太大了。

What I'm looking for is a way to keep creating more and more input fields, each with a browse button and then with one final upload button at the bottom of the form. Creating the new input fields with a Javascript is nog big deal really.

所以我想知道这是如何工作的。我是否需要为所有文件输入字段赋予相同的名称属性,以便我可以使用1段PHP代码来解决这个问题?或者是否有一些方法可以让PHP检测出如何汇总多个文件并简单地将代码解析为for-loop中的文件?

So I'm wondering how this works. Do I need to give all file-input fields the same name atribute so I can use 1 piece of PHP code to solve this? Or Is there some way for PHP to detect howmany files have been sumbitted and simply put the code for parsing a file inside a for-loop?

推荐答案

以下是算法:

您可以将新文件输入字段添加到表单中。每个字段必须具有唯一的名称。然后,在服务器端,循环遍历$ _FILES数组,查看已上载的文件数量并进行处理。

You add the new file input fields to your form. Each of this field MUST have a unique name. Then, on the server side, you loop through the $_FILES array looking how many files have been uploaded and handling them.

这篇关于使用PHP / Javascript进行多文件上传,无闪存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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