如何让Opera上传文件像其他浏览器一样? [英] How do I make Opera upload files like other browsers?

查看:98
本文介绍了如何让Opera上传文件像其他浏览器一样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Opera中使用< input type =file/> >上传一个文件时,它会按预期工作。也就是说,您可以在PHP服务器端的$ _​​FILES中找到预期的文件数据。



但是,当我尝试使用Opera一次性上传多个文件时,通过设置< input type =filemin =1max =999/> 然后所有文件的内容都粘在一个长字符串中并作为POST数据发送。这个字符串中的所有文件都被这样的标题分开:

  ------------ 94QV8HRqBwta8NY4L2WH0r 
Content-Disposition:form-data; NAME = 文件[]; filename =xxx1069225496.xml
Content-Type:text / xml

<?xml>
...

我知道Opera遵循Webforms 2.0标准。但是,有没有一种简单的方法可以使Opera以与其他浏览器相同的方式发送多个文件,或者我必须编写一个解释器才能从Opera获取文件?



谢谢你的帮助。以下是我目前使用的HTML。






 < div id = filearea > 
< / div>






这是$ _POST的var_dump的外观我已经删除了任何实际的XML数据,占用了空间)

$ $ $ $ $ $ $ c $ array $ {
[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-处置: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?>
...

}
}


解决方案

I刚刚检查了一个PHP bug报告,并声称这在Opera中有效:

 < input type =filename =filemin =1max =999/> 

但这不是:

 < input type =filename =file []min =1max =999/> 

编辑:测试完这个之后,我相信将bug标记为伪造的PHP人员并不知道他在说什么......我无法用PHP自带任何一种工作方式。



据我所知,PHP不支持Opera的混合文件上传。这不是Opera的一部分,因为他们正按照RFC的规范来实现它。我相信其他浏览器只需上传文件,就好像有多个输入元素一样。您可以通过检查_POST数组轻松地添加对此的支持:

  $ file = $ _POST ['file'] [0] ; 

while(preg_match('/ ^( - + [A-Za-z0-9] +)\s + /',$ file,$ matches))
{
$ id = $ matches [1];

$ i = strlen($ matches [0]);
$ body = false;
$ headers = array();
while(($ j = strpos($ file,\\\
,$ i))!== false)
{
$ line = substr($ file,$ i, $ j - $ i);
$ i = $ j + 1;
if(trim($ line)=='')
{
$ body = true;
休息;
}

list($ key,$ val)= explode(':',trim($ line),2);
$ headers [$ key] = trim($ val);
}
if(!$ body)break;

$ j = strpos($ file,$ id,$ i);

$ data = substr($ file,$ i,$ j- $ i);
echo $ data。< HR>; //也检查$ header

$ file = substr($ file,$ j);
}

在上面的代码中可能会有一些错误的错误。 p>

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"?>
...
    "
  }
}

解决方案

I just checked a PHP bug report, and it claimed that this works in Opera:

<input type="file" name="file" min="1" max="999" />

But that this does not:

<input type="file" name="file[]" min="1" max="999" />

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:

   $file = $_POST['file'][0];

   while (preg_match('/^(-+[A-Za-z0-9]+)\s+/', $file, $matches))
   {
      $id = $matches[1];

      $i = strlen($matches[0]);
      $body = false;
      $headers = array();
      while (($j = strpos($file, "\n", $i)) !== false)
      {
         $line = substr($file, $i, $j - $i);
         $i = $j + 1;
         if (trim($line) == '')
         {
            $body = true;
            break;
         }

         list($key, $val) = explode(':', trim($line), 2);
         $headers[$key] = trim($val);
      }
      if (!$body) break;

      $j = strpos($file, $id, $i);

      $data = substr($file, $i, $j-$i);
      echo $data."<HR>"; // also check $headers

      $file = substr($file, $j);
   }

There may be some off-by one errors in the above code.

这篇关于如何让Opera上传文件像其他浏览器一样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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