views:

449

answers:

8

Ive created an uplaod 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 dont upload an image, then the script can be found and is run.

I tried in safari, and i dont get the same problem, i can upload an image from the form, it will process it and take me the correct page.

Ive 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 wont get to the script, if no image is present, it runs fine.

Im just wondering if anyone has any idea whats going on?


=Update=

Okay, so ive still got this problem, i seem to think ive found out whats causing it then, but then i find something that contradicts it completley.

At the moment, ive 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 cant, it just resets the connection after "Loading..." for a bit.

Also, ive noticed that i can Ctrl+F5 a few times and get another uplaod through.

Althought there are ways around this, i dont want to have a form that requires users to clear cookies or refresh everytime they need to upload. And as ive mentioned before, this error does not occor in IE/Opera/Safari/Chrome.

It seems like firefox is storing something, im not sure what. Any help would be greatfully appretiated.

If it helps here is the code im 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 whats going on. If none of them are actually being output. So for some reason the form is not being submitted. Which is why its not getting to the script. Ive no idea why tho. Ive got no css, or js errors.

== Update ==

Okay ive being trying some more things and still no luck, the html, css, js is all valid. Ive done an IIS Reset, ive recreated my firefox profile. And still now luck.

I was testing it again, and this time i stoped 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 doesnt 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. Im 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 anymore insight, please post below. Its much appretiated :)

A: 

Even with the following simple upload script, nothing happens.

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

  if (isset($_FILES['file']['name'])) {
        $target_path = "public/photos/";

        $target_path = $target_path . basename($_FILES['file']['name']);

        if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
            echo "The file ".  basename( $_FILES['file']['name']).
            " has been uploaded";
        } else{
            echo "There was an error uploading the file, please try again!";
        }

  }
}

Any ideas?

cast01
A: 

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.

Sarfraz
Thanks for the help, but the process isnt even getting this far. I made the change anyway, and tested bu no luck.im calling it from http://localhost/upload/index.phpthe form has been set to send data to upload.php in the same directory.If there is an image selected, when i click submit, it just hangs on index.php with the loading animation goin round.Ive no idea why.
cast01
@cast01: make sure that you have write permission to the directory chmod to 755
Sarfraz
Thanks again, but still no luck. Im completley stumped.
cast01
A: 

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.

Marco Demajo
Hey, thanks, initially i thought it might be my version of FF but im still using 3.5, and the uploads vary, most are only 200-300KB.
cast01
A: 

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"&gt;

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

cast01
A: 

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

Martin
yeah, all looks fine in the page source. Page is constructed correctly.
cast01
if you want you can post it, just to make sure.
Martin
A: 

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.

ccheneson
hi there, i took ur advice and added an id="myform" to the form tag, and still i get the same behaviour.I think it could still be the validation though, as ive messed around with different doc types, at one point i had it as transitional, and the problem happened more often. (I dont know if they are related issues or just a coincedence at this stage however.
cast01
As I said above(in the OP), try with a "standard" html without being xhtml compliant and see if it fires your php script
ccheneson
Okay, well ive changed doctype to transitional, ran it through the validator and its valid, also my web developers toolbar is showing no html/css/js errors. The problem seems to be happening less often, but not less enough for me to discount it.
cast01
Just seen your comment, ill try standard now :)
cast01
Ive tried standard, using <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> and getting pretty much the same thing
cast01
Try adding some javascript onSubmit with an alert to see if the submit button actually triggers something.
ccheneson
Ahh, i added the javascript, and the form seems to be submitted. i added 'onSubmit="alert('submitted')"' and this alert is displayed, even when the script isnt called. I cant think why this is happeneing though. Its getting stuck somewhere in the middle.
cast01
Ive also logged values to the firebug console, and input seems to be picked up correctly.
cast01
One more test:Instead of using echo $_SERVER["PHP_SELF"]; to generate dynamically the action in your form, can you hardcode the name of the target php script and try it again?If it doesnt work, you will just have to hire an exorcist to kill the daemon inside your workstation :)
ccheneson
once again no luck, i have absolultey no idea whats causing this. Thanks for the suggestions though, much appretiated! :)
cast01
Another idea, change the method from "post" to "get" and see if it calls the php script. I find this problem weird .. and interesting :)
ccheneson
Nice idea, i tried it, and the from is called, although the iamge just isnt passed. I think i mave have found the daemon in my workstation....AVG Linkscanner. I disabled it and uploads seem to be getting through. However i dont want to have to disable it, or tell users to disable it to upload files.
cast01
Maybe using a post via ajax can bypass AVG Linkscanner.
ccheneson
Yeah ill give that a try, and once again, thanks for the help :) Its a shame though, since i want to have graceful degradation and if the non js users have to start disabling things for successful uploads its bit messy
cast01
I have use this link http://validator.w3.org/ to check your xhtml in your OP and it reports some errors. Give it a try, if there are some errors, fix them and see. One of the error was to have the "post" method in lowercase
ccheneson
A: 

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

<pre>
    <?PHP
        print_r($_POST);
    ?>
</pre>
SaltLake
nice idea, but ive alreadt done a print_r on the $_POST values. In the cases that frirefox doesnt reset the connection, they are printed out correctly. However when it does reset, the script doesnt even get that far to see whats actually being posted. The form is submitted but its hanging in between.
cast01
A: 

THANK YOU!!!! THANK YOU!!!! I have been having this problem and I had tried everything to resolve it, but to no avail. When I put in:

enctype="multipart/form-data"

in the form tag, this resolved it. So stupid since I wasn't uploading a file, but this seemed to work.

THANK YOU!!!!!

Anonymous