简体   繁体   English

Firefox上传表单问题

[英]Firefox Upload Form Issue

I've created an upload script in php that takes a file, resizes it, and creates a cropped square thumbnail. 我在php中创建了一个上传脚本,它接受一个文件,调整大小,并创建一个裁剪的方形缩略图。 The script itself seems to work fine. 脚本本身似乎工作正常。

However, when I tried to upload an image through Firefox, on clicking the submit button the browser shows the loading animation, but it never calls the script, it just stays on the current page. 但是,当我尝试通过Firefox上传图像时,单击提交按钮时,浏览器会显示加载动画,但它从不调用脚本,它只保留在当前页面上。 If don't upload an image, then the script can be found and is run. 如果不上传图像,则可以找到并运行脚本。

I tried in safari, and I don't get the same problem, I can upload an image from the form, it will process it and take me the correct page. 我在safari中尝试过,我没有遇到同样的问题,我可以从表单上传图像,它会处理它并带我正确的页面。

I've tired just calling a basic script from the form, it just prints out the $_POST and $_FILES, and I get the same result, if an image is present, it won't get to the script, if no image is present, it runs fine. 我已经厌倦了从表单中调用一个基本脚本,它只打印出$ _POST和$ _FILES,我得到相同的结果,如果有图像,它将无法访问脚本,如果没有图像目前,它运行良好。

I'm just wondering if anyone has any idea what's going on? 我只是想知道是否有人知道发生了什么事?


=Update= = =更新

Okay, so I've still got this problem, I seem to think I've found out what's causing it then, but then I find something that contradicts it completely. 好吧,所以我仍然遇到这个问题,我似乎认为我已经找到了导致它的原因,但后来我发现了一些完全与之相矛盾的东西。

At the moment, I've noticed that I can successfully upload after I clear my Firefox cache, but I can only upload one image, then when I try to upload another, I can't, it just resets the connection after "Loading..." for a bit. 目前,我已经注意到我可以在清除我的Firefox缓存后成功上传,但我只能上传一个图像,然后当我尝试上传另一个时,我不能,它只是在“加载后”重置连接。 ..“ 就一点点。

Also, I've noticed that I can Ctrl+F5 a few times and get another upload through. 另外,我注意到我可以按Ctrl + F5几次并再次上传。

Although there are ways around this, I don't want to have a form that requires users to clear cookies or refresh every time they need to upload. 虽然有办法解决这个问题,但我不希望有一个表单需要用户清除cookie或每次需要上传时刷新。 And as I've mentioned before, this error does not occur in IE/Opera/Safari/Chrome. 正如我之前提到的,IE / Opera / Safari / Chrome中不会出现此错误。

It seems like Firefox is storing something, I'm not sure what. 好像Firefox存储的东西,我不知道是什么。 Any help would be gratefully appreciated. 任何帮助将不胜感激。

If it helps here is the code I'm using. 如果它有帮助,我正在使用的代码。

The HTML Form HTML表单

<form enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="POST">
<label for="file">Choose a file to upload</label>
<input id="file" name="file" type="file" /><br />
<input type="submit" value="Upload File" name="submit" />

And the PHP: 和PHP:

if (isset($_POST['submit'])) {

  echo "Processing...<br/>";

  if (isset($_FILES['file']['name'])) {
      $file_array = $_FILES['file'];

      echo "Uploading...";
      upload File($file_array);
      echo "...Done";

  }
}

The echos are for me to see what's going on. 回声让我看看发生了什么。 If none of them are actually being output. 如果它们实际上都没有输出。 So for some reason the form is not being submitted. 因此,由于某种原因,表格未提交。 Which is why it's not getting to the script. 这就是为什么它没有进入脚本。 I've no idea why though. 我不知道为什么。 I've got no CSS, or JavaScript errors. 我没有CSS或JavaScript错误。

== Update == ==更新==

Okay I've being trying some more things and still no luck, the HTML, CSS and JavaScript is all valid. 好吧,我正在尝试更多的东西,但仍然没有运气,HTML,CSS和JavaScript都是有效的。 I've done an IIS Reset, I've recreated my Firefox profile. 我已经完成了IIS重置,我重新创建了我的Firefox配置文件。 And still now luck. 现在还好运。

I was testing it again, and this time I stopped it in the middle of loading (before the connection was reset) and then tried to go to a different page of the website, and the freezing continued, it would still say "Loading..." and "Waiting for localhost...". 我再次测试它,这次我在加载过程中停止了它(在连接重置之前)然后尝试去网站的另一页,并且冻结继续,它仍然会说“正在加载.. 。“和”等待本地主机......“。 Not really sure what to make of that, is it some settings that I have? 不知道该怎么做,我有一些设置吗? But then why doesn't it affect other browsers? 但那么为什么它不影响其他浏览器呢?

== Update == ==更新==

As I mentioned below, it seems that AVG Linkscanner/Active surf shield seems to causing this issue, and there are many reports of others having similar problems with it. 正如我在下面提到的,似乎AVG Linkscanner / Active冲浪盾似乎导致了这个问题,并且有很多其他人报告有类似问题。 I updated from AVG Free v9.0.733 to v9.0.790 and I STILL have the same problem. 我从AVG Free v9.0.733更新到v9.0.790,我仍然遇到同样的问题。 I'm going to browse the AVG support forums and maybe post something over there since it seems to be an AVG issue. 我打算浏览AVG支持论坛,也许在那里发布一些东西,因为它似乎是一个AVG问题。

If anyone does have any more insight, please post below. 如果有人有任何更多的见解,请在下面发布。 It's much appreciated :) 非常感谢:)

Okay, im getting somewhere with this, you may think this is just a stupid mistake but read on. 好吧,即便到这个地方,你可能会认为这只是一个愚蠢的错误,但请继续阅读。

If i dont have the < html >< body >..etc tags and just have.. 如果我没有<html> <body> .. etc标签,只是...

<form enctype="multipart/form-data" action="up.php" method="POST">
    <label for="file">Choose a file to upload</label>
    <input id="file" name="file" type="file" /><br />
    <input type="submit" value="Upload File" name="submit" />
</form>

Then i get this issue, where firefox will hang, on form submission. 然后我得到这个问题,firefox将在表单提交时挂起。

If i have the correct tags like.. 如果我有正确的标签,如..

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 


<head>
<title></title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>

<body >

    <form enctype="multipart/form-data" action="up.php" method="POST">
    <label for="file">Choose a file to upload</label>
    <input id="file" name="file" type="file" /><br />
    <input type="submit" value="Upload File" name="submit" />
    </form>

</body>

</html>

Then it seems that this works. 然后它似乎有效。 Now this looks simple, but i build my pages up dynamically so i just have one file that contains just the form code that gets included in the page. 现在这看起来很简单,但我动态构建我的页面,所以我只有一个文件,其中只包含页面中包含的表单代码。

Thats as far as ive got, althought having the form code in a separate file should make no difference since its all put together server side. 就目前而言,虽然在单独的文件中使用表单代码应该没有区别,因为它全部放在一起服务器端。

Sometimes, relative paths are perceived differently by different browsers, not that sure actually but try to specify current directory by prefixing path with ./ , eg: 有时候,不同的浏览器会对不同的相对路径产生不同的感知,但实际上并不确定,而是尝试通过使用./前缀路径来指定当前目录 ,例如:

$target_path = "./public/photos/";

Rest of the code looks fine to me. 其余代码对我来说很好看。

Just in case you are using the latest FF 3.6 I'm experiencing exactly the same problem, Any form loading a big file (1MB it's enought) seem to block FF upload. 如果您使用的是最新的FF 3.6,我遇到了完全相同的问题,任何加载大文件的表单(1MB)都会阻止FF上传。 On IE7/Safari/Opera it works. 在IE7 / Safari / Opera上它可以工作。

然后当你右键单击FF并查看源代码时,它应该看起来与上面的代码完全一样(在“如果我有正确的标签,如......”下面)。

From the xhtml 1.0 specification 来自xhtml 1.0规范

HTML 4 defined the name attribute for the elements a, applet, form, frame, iframe, img, and map. HTML 4定义了元素a,applet,form,frame,iframe,img和map的name属性。 HTML 4 also introduced the id attribute. HTML 4还引入了id属性。 Both of these attributes are designed to be used as fragment identifiers. 这两个属性都被设计为用作片段标识符。

In XML, fragment identifiers are of type ID, and there can only be a single attribute of type ID per element. 在XML中,片段标识符的类型为ID,每个元素只能有一个ID类型的属性。 Therefore, in XHTML 1.0 the id attribute is defined to be of type ID. 因此,在XHTML 1.0中,id属性被定义为ID类型。 In order to ensure that XHTML 1.0 documents are well-structured XML documents, XHTML 1.0 documents MUST use the id attribute when defining fragment identifiers on the elements listed above. 为了确保XHTML 1.0文档是结构良好的XML文档,在上面列出的元素上定义片段标识符时,XHTML 1.0文档必须使用id属性。

Maybe adding an id to the form could fix your problem. 也许在form添加id可以解决您的问题。

Maybe shomething wrong with if (isset($_POST['submit'])) { and the variable $_POST['submit'] is not included by FireFox? 也许错误的if (isset($_POST['submit'])) {和FireFox不包含变量$_POST['submit']

<pre>
    <?PHP
        print_r($_POST);
    ?>
</pre>

This isn't going to help you much but I am having EXACTLY the same problem. 这对你没什么帮助,但我确实遇到了同样的问题。 I have even re-installed FF, cleared cache, stripped the code right down (to a very simple form without validation and with all PHP stripped out - both on load and on post back). 我甚至重新安装了FF,清除了缓存,向右删除了代码(一个非常简单的形式,没有验证,所有PHP都被剥离 - 无论是在加载还是在回发后)。 I have the problem in FF 3.6.13 and have tested against current versions of Safari(win), Chrome, Opera and IE where the code all works perfectly. 我在FF 3.6.13中遇到了问题,并且针对当前版本的Safari(win),Chrome,Opera和IE进行了测试,其中代码都完美无缺。 My code validates as strict XHTML and all the suggestions above are already in there... what's more I am using my local (on the same computer) web site. 我的代码验证为严格的XHTML,上面的所有建议已经在那里......我正在使用我的本地(在同一台计算机上)网站。

MANY thanks for pointing me towards AVG Link scanner... disabling it does fix the problem but that still leaves me thinking FF has a bug as "all" other browsers play nicely with the AVG Link scanner on. 非常感谢您指出我对AVG链接扫描仪...禁用它确实解决这个问题,但仍然让我思考FF有一个错误的“所有”其他浏览器上的AVG链接扫描仪发挥很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM