Jump to content

Upload only if submit has been clicked


J-C

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/195163-upload-only-if-submit-has-been-clicked/
Share on other sites

Sounds like this is the logic you need.

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

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:

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.