$_FILES Problem

Hi

I’m having a problem with $_FILES, I have a form which refreshs its self display all the data which was entered by the user, the user may unload one picture for there profile on submit click the picture uploads fine and is stored into a folder the problem I have is that if the user presses the f5 the fresh button the picture is added again to the folder, what i would like to know is there a way of stopping this, I have been working with some code and nothing seems to work



if(isset($_FILES['file']))
{
  
move_uploaded_file($_FILES["file"]["tmp_name"],$url  .      $_SESSION['server_side']['sexdropbox'] . "-"
. time() . "-" . $_FILES["file"]["name"]);
unset($_FILES);
			
}


when someone hits refresh, the script is run again.

So the best thing to do is have the upload script in one file, and redirect with the other.

So:

  1. The form submits to upload.php
  2. upload.php uploads the file, then redirects to viewUpload.php. It sends information e.g. the filename etc through either a session or $_GET
  3. viewUpload.php simply views the uploaded file information. Upon refreshing, it simply just loads the viewing part without sending any form information

What you mean? Do you mean you worked successfully to upload the file via AJAX? It is not easy to upload the files with AJAX. So better and safe way to upload the files would be to use the page reloading and do what Jake has already suggested. If you don’t want to create multiple pages then you can even manage everything in a single file too:

Suppose your file is upload.php:


<?hp
if($_SERVER['REQUEST_METHOD'] == 'POST'){
    // do upload the file
    // redirect the same page upload.php
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
	<meta name="author" content="Raju Gautam" />

	<title>Untitled 1</title>
</head>
<body>
<form method="post" action="upload.php" name="frm1">
    // your form goes here....
</form>
</body>
</html>

Thanks i was thinking of something on those lines, out of interest can i do something with AJAX to solve this problem, has i have just got my first AJAX script working today.

Thanks