Page 1 of 1

File uploading issue - file uploads on browser refresh

Posted: Thu Aug 10, 2006 4:55 am
by rzabin
Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello  All,

I am using the following code to upload file to server. I am having  a strange problem that the file does not
upload the first time PHP is called from HTML form, when he browser is refreshed i.e. the script is executed again
the file gets uploaded to the desired location. Please help me solve my problem.


HTML Form:

Code: Select all

<FORM ACTION="fileUpload1.php" METHOD=POST ENCTYPE="multipart/form-data"> 
<INPUT TYPE="file" NAME="uploadedfile" SIZE=30> 
<INPUT TYPE="submit" VALUE="Upload File"> 
</FORM>

PHP file:

Code: Select all

<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.

$uploaddir = '../';
$uploadfile = $uploaddir . basename($_FILES['uploadedfile']['name']);

echo '<pre>';
if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $uploadfile)) {
   echo "File is valid, and was successfully uploaded.\n";
} else {
   echo "Possible file upload attack!\n";
}

echo 'Here is some more debugging info:';
print_r($_FILES);

print "</pre>";

?>
php.ini values:

Code: Select all

file_uploads = On
;upload_tmp_dir = 
upload_max_filesize = 2M
I have tried with upload_tmp_dir = "c:\winnt\temp\" also but the issue remains the same.

Regards,
Rifat


Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Thu Aug 10, 2006 6:01 am
by s.dot
Does your script indicate that the file HAS been uploaded after the initial try? What about after the refresh? Seems like a strange problem.

Posted: Thu Aug 10, 2006 6:37 am
by blackbeard
The only thing that I see wrong right off the bat is that you need to put quotation marks around METHOD and SIZE attributes in your HTML form. See below

Code: Select all

<FORM ACTION="fileUpload1.php" METHOD="POST" ENCTYPE="multipart/form-data">
<INPUT TYPE="file" NAME="uploadedfile" SIZE="30">
<INPUT TYPE="submit" VALUE="Upload File">
</FORM>
Can't say if this will fix it or not, but it's an easy start. Can you show us the output of the php code?

Posted: Thu Aug 10, 2006 11:22 pm
by rzabin
scottayy wrote:Does your script indicate that the file HAS been uploaded after the initial try? What about after the refresh? Seems like a strange problem.
yes it notifies for the first time that the file has been successfully uploaded and on refresh also it gives the same message. And thereafter if I refresh it gives me the message to notify that the file already exists.