如何让 Opera 像其他浏览器一样上传文件?
在 Opera 中使用 上传一个文件时,它会按预期工作。也就是说,您可以在 PHP 服务器端的 $_FILES 中找到所需的文件数据。
但是,当我尝试使用 Opera 一次上传多个文件时,通过设置 然后所有文件的内容粘合在一起形成一长串并作为 POST 数据发送。该字符串中的所有文件均由如下标头分隔:据
------------94QV8HRqBwta8NY4L2WH0r
Content-Disposition: form-data; name="file[]"; filename="xxx1069225496.xml"
Content-Type: text/xml
<?xml>
...
我所知,Opera 遵循 Webforms 2.0 标准。但是有没有一种简单的方法可以让 Opera 以与其他浏览器相同的方式发送多个文件,或者我必须编写一个解释器来仅从 Opera 获取文件?
感谢您的任何帮助。下面是我当前使用的 HTML。
<div id="filearea">
<input type="file" min="1" max="6000" accept="text/xml" name="file[]" style="padding: 1px; margin: 2px 0px;" />
</div>
这就是 $_POST 的 var_dump 的样子(我已经删除了任何实际的 XML 数据,占用了空间)
array(1) {
["file"]=>
array(1) {
[0]=>
string(4209) "------------94QV8HRqBwta8NY4L2WH0r
Content-Disposition: form-data; name="file[]"; filename="1219854274.xml"
Content-Type: text/xml
<?xml version="1.0"?>
...
------------94QV8HRqBwta8NY4L2WH0r
Content-Disposition: form-data; name="file[]"; filename="xxx1069225496.xml"
Content-Type: text/xml
<?xml version="1.0"?>
...
------------94QV8HRqBwta8NY4L2WH0r
Content-Disposition: form-data; name="file[]"; filename="xxx1111008062.xml"
Content-Type: text/xml
<?xml version="1.0"?>
...
------------94QV8HRqBwta8NY4L2WH0r
Content-Disposition: form-data; name="file[]"; filename="1219854274.xml"
Content-Type: text/xml
<?xml version="1.0"?>
...
"
}
}
When uploading one file using <input type="file" />
in Opera, it works as expected. That is, you find the expected file data in $_FILES in PHP server side.
However, when I try to upload several files at once using Opera, by setting <input type="file" min="1" max="999" />
then all the files' contents are glued together in one long string and sent as POST data. All the files in this string are separated by headers such as this:
------------94QV8HRqBwta8NY4L2WH0r
Content-Disposition: form-data; name="file[]"; filename="xxx1069225496.xml"
Content-Type: text/xml
<?xml>
...
Opera follows the Webforms 2.0 standard, I know. But is there a simple way to make Opera send multiple files in the same fashion other browsers do, or will I have to write an interpreter to get files just from Opera?
Thanks for any help. Below is the HTML I'm currently using.
<div id="filearea">
<input type="file" min="1" max="6000" accept="text/xml" name="file[]" style="padding: 1px; margin: 2px 0px;" />
</div>
This is how the var_dump of $_POST looks (I've erased any actual XML data, taking up space)
array(1) {
["file"]=>
array(1) {
[0]=>
string(4209) "------------94QV8HRqBwta8NY4L2WH0r
Content-Disposition: form-data; name="file[]"; filename="1219854274.xml"
Content-Type: text/xml
<?xml version="1.0"?>
...
------------94QV8HRqBwta8NY4L2WH0r
Content-Disposition: form-data; name="file[]"; filename="xxx1069225496.xml"
Content-Type: text/xml
<?xml version="1.0"?>
...
------------94QV8HRqBwta8NY4L2WH0r
Content-Disposition: form-data; name="file[]"; filename="xxx1111008062.xml"
Content-Type: text/xml
<?xml version="1.0"?>
...
------------94QV8HRqBwta8NY4L2WH0r
Content-Disposition: form-data; name="file[]"; filename="1219854274.xml"
Content-Type: text/xml
<?xml version="1.0"?>
...
"
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚检查了一份 PHP 错误报告,它声称这在 Opera 中有效:
但这不起作用:
编辑:经过测试,我相信将错误标记为虚假的 PHP 人不知道他在说什么。 ..我无法通过任何一种方式使用 PHP 进行本地工作。
据我所知,PHP 不支持 Opera 的“混合”文件上传。这不是 Opera 的错误,因为他们是按照 RFC 的规范来实现的。我相信其他浏览器只是上传文件,就好像有多个输入元素一样。您可以通过检查 _POST 数组轻松添加对此的支持:
上面的代码中可能存在一些相差一的错误。
I just checked a PHP bug report, and it claimed that this works in Opera:
But that this does not:
Edit: After testing this, I believe the PHP person who marked the bug as bogus didn't know what he was talking about... I cannot get either way to work natively with PHP.
As far as I can tell, PHP does not support Opera's 'mixed' file uploads. This is not a bug on Opera's part, as they are implementing it per the RFC's specification. I believe the other browsers simply upload the files as if there were multiple input elements. You could easily add support for this by checking the _POST array:
There may be some off-by one errors in the above code.