File uploading issue - file uploads on browser refresh

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rzabin
Forum Newbie
Posts: 4
Joined: Tue Jun 06, 2006 2:54 am

File uploading issue - file uploads on browser refresh

Post 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]
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
blackbeard
Forum Contributor
Posts: 123
Joined: Thu Aug 03, 2006 6:20 pm

Post 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?
rzabin
Forum Newbie
Posts: 4
Joined: Tue Jun 06, 2006 2:54 am

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