Author Topic: Upload only if submit has been clicked  (Read 264 times)

0 Members and 1 Guest are viewing this topic.

Offline J-CTopic starter

  • Irregular
  • Posts: 33
    • View Profile
Upload only if submit has been clicked
« on: March 13, 2010, 10:02:24 PM »
Ok my main problem is that When I refresh a page ( upload.php ) it uploads the file even if the form has not been submitted through the upload page ( index.php ), so essentially what I want is that when I refresh the page where I uploaded the file, instead of re-uploading to just keep the last uploaded file instead.

Would this be achieved through sessions? if so can anyone help me please, because is really annoying that it just keeps re-uploading when I press refresh.
« Last Edit: March 13, 2010, 10:11:12 PM by J-C »

Offline teamatomic

  • Devotee
  • Posts: 1,197
  • Gender: Male
  • fat skis rule!
    • View Profile
    • myPHPtemplate
Re: Upload only if submit has been clicked
« Reply #1 on: March 13, 2010, 10:34:06 PM »
Sounds like this is the logic you need.
Code: [Select]
session_start();
if (isset($_SESSION['key']))
{
echo "FILE ALREADY SENT";
      exit;
}
if(isset($_POST['submit']))
{
$_SESSION['key']=$_POST['key'];

}
echo "{$_POST['tester']}";
?>
<form method=post action=''>
<input type='hidden' name='key' value='AvR5G6dS34'/>
<input type='text' name='tester' value=''/>
<br>
<input type='submit' name='submit' value='submit'/>
</form>


HTH
Teamatomic
when in doubt...ski fast
when scared...ski faster
when terrified...point em down

Offline J-CTopic starter

  • Irregular
  • Posts: 33
    • View Profile
Re: Upload only if submit has been clicked
« Reply #2 on: March 13, 2010, 11:08:16 PM »
Is it supposed to be in the same file? because the form is in index.php and the upload script is in upload.php, this is the form:

Code: [Select]
<form action="upload.php" method="POST" enctype="multipart/form-data"
name="upform" onSubmit="return No_file();">
<div class="input">
Image to upload: <br />
<input type="file" name="upload" />
 <br />
 </div>
<center> <input type=submit name=Submit value="Upload Image" /> </center>
</form>