$_Files[] 数组仅显示上传的第一个文件
我目前有一个带有单个文件上传输入的表单。
我尝试过的原始表单输入
<input type="file" name="userFile[]" />
and
<input type="file" name="userFile1" />
我还有一个链接,可以使用
以下方法生成更多输入字段:
a)
counter = 1;
function addInput(){
counter ++;
$('#divName').append('<input type="file" name="userFile[]" ' />);
}
b)
var counter = 1;
function addInput(){
counter++;
$('#divName').append('<input type="file" name="userFile'+counter+'" ' />);
}
我认为这个问题与 JS 无关,但我认为可能与服务器有关。
问题是,当我最终按下“提交”按钮并将文件传递到服务器并尝试访问所有 $_FILES['userFile']['name']
/['size ']
/['error']
等值,只有第一个原始表单上传值可以被回显/打印。我尝试上传大尺寸文件进行测试,我知道所有文件都已上传,但一旦到达服务器端,就只能访问一个文件。
谁能告诉我可能发生的事情吗? 我希望我解释得正确,如果您需要澄清,请询问我任何问题。
更多信息
经过更多测试后,看来 Jquery 可能是问题所在。 在上述复制字段的方法中,上传文件时仅识别第一个原始输入。
但是,如果我创建三个原始输入字段并正常上传到它们,则 $_FILES
数组中的所有文件都会被识别为应有的样子。
那么为什么 jQuery 生成的字段没有在表单中发布呢?
I currently have a form with a single file upload input on it.
the original form input I've tried
<input type="file" name="userFile[]" />
and
<input type="file" name="userFile1" />
I also have a link to generate more input fields using
If have tried methods of:
a)
counter = 1;
function addInput(){
counter ++;
$('#divName').append('<input type="file" name="userFile[]" ' />);
}
b)
var counter = 1;
function addInput(){
counter++;
$('#divName').append('<input type="file" name="userFile'+counter+'" ' />);
}
I don't think the issue is JS related here but possibly the server I think.
The issue is that when I finally press the Submit button and pass the files to the server and try to access all the $_FILES['userFile']['name']
/['size']
/['error']
etc values, only the very first original form upload values can be echoed/printed. I tried uploading large size files for testing I know that all files are getting uploaded but once it gets to the server side, only one can be accessed.
Can anyone give me a point as to what might be going on?
I hope I explained this right, ask me any questions if you need clarification.
more info
after some more testing it looks like Jquery might be the issue after all.
In the above method mentioned of duplicating the fields, only the first original input is recognized when the files are uploaded.
But if I create three original input fields and upload to them as normal then all files in the $_FILES
array are recognized as they should be.
So why are the jQuery generated fields not posting in the form?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了同样的问题..我所有的努力都是徒劳的,但最后我在 PHP 手册中找到了一个很好的注释。它很简单,但非常适合我......
请点击此链接查看完整说明,有一个函数可以重新排列多个上传文件数组以易于使用的方式
http://php.net/手册/en/features.file-upload.multiple.php
I had the same problem.. All my efforts were in vain, but finally I found a pretty good note at the PHP Manual. It's simple but suited me perfectly...
Follow this link for the full note, there is a function to rearrange the multiple upload file array in a easy-to-use manner.
http://php.net/manual/en/features.file-upload.multiple.php