Firefox 上传表单问题

发布于 2024-08-23 00:51:11 字数 1979 浏览 3 评论 0原文

我在 php 中创建了一个上传脚本,它接受一个文件,调整它的大小,并创建一个裁剪后的方形缩略图。脚本本身似乎运行良好。

但是,当我尝试通过 Firefox 上传图像时,单击提交按钮时,浏览器会显示加载动画,但它从未调用脚本,它只是停留在当前页面上。如果不上传图像,则可以找到脚本并运行。

我在 safari 中尝试过,没有遇到同样的问题,我可以从表单上传图像,它会处理它并带我到正确的页面。

我已经厌倦了从表单中调用基本脚本,它只是打印出 $_POST 和 $_FILES,并且我得到相同的结果,如果存在图像,则它不会到达脚本,如果没有图像目前,运行良好。

我只是想知道是否有人知道发生了什么事?


=Update=

好的,所以我仍然遇到这个问题,我似乎认为我已经找到了导致它的原因,但后来我发现了一些东西完全矛盾。

目前,我注意到清除 Firefox 缓存后可以成功上传,但我只能上传一张图像,然后当我尝试上传另一张图像时,我不能上传,它只是在“加载中”后重置连接。 ..”一会儿。

另外,我注意到我可以按 Ctrl+F5 几次并再次上传。

尽管有很多方法可以解决这个问题,但我不希望有一个表单要求用户在每次需要上传时清除 cookie 或刷新。正如我之前提到的,这个错误不会发生在 IE/Opera/Safari/Chrome 中。

Firefox 似乎正在存储一些东西,我不确定是什么。 任何帮助将不胜感激。

如果这里有帮助,那就是我正在使用的代码。

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" />

和 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";

  }
}

回声是为了让我看看发生了什么。如果实际上没有一个被输出。因此,由于某种原因,该表格没有被提交。这就是为什么它没有进入脚本。我不知道为什么。我没有遇到 CSS 或 JavaScript 错误。

== 更新==

好吧,我已经尝试了更多的事情,但仍然没有成功,HTML、CSS 和 JavaScript 都是有效的。我已经完成了 IIS 重置,并重新创建了我的 Firefox 配置文件。现在仍然很幸运。

我再次测试它,这次我在加载过程中停止了它(在重置连接之前),然后尝试转到网站的其他页面,并且冻结继续,它仍然会说“正在加载.. .”和“正在等待本地主机...”。不太确定该怎么做,是我有一些设置吗?但为什么它不影响其他浏览器呢?

== 更新==

正如我在下面提到的,AVG Linkscanner/Active surfshield 似乎是导致此问题的原因,并且有许多报告表明其他人也遇到类似问题。我从 AVG Free v9.0.733 更新到 v9.0.790,但仍然遇到同样的问题。我将浏览 AVG 支持论坛,也许会在那里发布一些内容,因为这似乎是 AVG 问题。

如果有人有更多见解,请在下面留言。非常感谢:)

I've created an upload script in php that takes a file, resizes it, and creates a cropped square thumbnail. 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. 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.

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.

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.

Also, I’ve noticed that I can Ctrl+F5 a few times and get another upload through.

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. And as I’ve mentioned before, this error does not occur in IE/Opera/Safari/Chrome.

It seems like Firefox is storing something, I’m not sure what.
Any help would be gratefully appreciated.

If it helps here is the code I’m using.

The HTML Form

<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:

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.

== Update ==

Okay I’ve being trying some more things and still no luck, the HTML, CSS and JavaScript is all valid. I’ve done an IIS Reset, I’ve recreated my Firefox profile. 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. I updated from AVG Free v9.0.733 to v9.0.790 and I STILL have the same problem. I’m going to browse the AVG support forums and maybe post something over there since it seems to be an AVG issue.

If anyone does have any more insight, please post below. It’s much appreciated :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

誰ツ都不明白 2024-08-30 00:51:11

好吧,我已经了解了这一点,你可能认为这只是一个愚蠢的错误,但请继续阅读。

如果我没有 < 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>

然后我遇到这个问题,在表单提交时,firefox 将挂起。

如果我有正确的标签,例如..

<!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>

那么这似乎有效。现在这看起来很简单,但我动态构建页面,因此我只有一个文件,其中仅包含页面中包含的表单代码。

据我所知,尽管将表单代码放在单独的文件中应该没有什么区别,因为它全部放在服务器端。

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..

<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.

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.

别理我 2024-08-30 00:51:11

有时,不同浏览器对相对路径的感知不同,实际上不确定,但尝试通过在路径前添加 ./ 来指定当前目录,例如:

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

其余代码对我来说看起来不错。

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.

无敌元气妹 2024-08-30 00:51:11

万一您使用的是最新的 FF 3.6,我遇到了完全相同的问题,任何加载大文件(1MB 就足够了)的形式似乎都会阻止 FF 上传。
在 IE7/Safari/Opera 上它可以工作。

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.
On IE7/Safari/Opera it works.

笑红尘 2024-08-30 00:51:11

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

Then when you right click in FF and view source, it should look exactly like it does in your code above (below "If i have the correct tags like..").

网白 2024-08-30 00:51:11

来自 xhtml 1.0 规范

HTML 4 定义了 name 属性
元素 a、applet、form、frame、
iframe、img 和地图。 HTML 4 也
引入了 id 属性。两者都
这些属性被设计为
用作片段标识符。

在 XML 中,片段标识符是
type ID,并且只能有一个
每个 ID 类型的单个属性
元素。因此,在 XHTML 1.0 中
id 属性被定义为类型
ID。为了确保XHTML 1.0
文档是结构良好的 XML
文档,XHTML 1.0 文档必须
定义时使用 id 属性
元素上的片段标识符
上面列出了。

也许向 form 添加 id 可以解决您的问题。

From the xhtml 1.0 specification

HTML 4 defined the name attribute for
the elements a, applet, form, frame,
iframe, img, and map. HTML 4 also
introduced the id attribute. 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. Therefore, in XHTML 1.0 the
id attribute is defined to be of type
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.

Maybe adding an id to the form could fix your problem.

尴尬癌患者 2024-08-30 00:51:11

也许 if (isset($_POST['submit'])) { 有问题,并且 FireFox 不包含变量 $_POST['submit']

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

Maybe shomething wrong with if (isset($_POST['submit'])) { and the variable $_POST['submit'] is not included by FireFox?

<pre>
    <?PHP
        print_r($_POST);
    ?>
</pre>
神回复 2024-08-30 00:51:11

这不会对你有太大帮助,但我遇到了完全相同的问题。我什至重新安装了 FF,清除了缓存,直接剥离了代码(到一个非常简单的形式,没有验证,并且所有 PHP 都被剥离 - 无论是在加载时还是在回发时)。我在 FF 3.6.13 中遇到了这个问题,并针对当前版本的 Safari(win)、Chrome、Opera 和 IE 进行了测试,其中代码都可以完美运行。我的代码被验证为严格的 XHTML,并且上面的所有建议都已经在那里......而且我正在使用我的本地(在同一台计算机上)网站。

很多感谢您向我指出AVG Link扫描仪...禁用它确实可以解决问题,但这仍然让我认为FF有一个错误,因为“所有”其他浏览器在AVG Link扫描仪打开的情况下都能很好地运行。

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). 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. 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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文