Solved

'PHP_SELF' refresh

Posted on 2008-10-15
3
1,110 Views
Last Modified: 2013-12-13
i use 'PHP_SELF' for file upload. it works fine ,but when i refresh the php page, it reloade the file again.

please help me.
<html>

<FORM enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">

<P> <input type="file" name="file"/>

<input type="hidden" name="MAX_FILE_SIZE" value="2000000" />

<INPUT type="submit" name="submit" value="UPLOAD"/>

</P>

</FORM>

</html>

<?php
 

   if(!empty($_POST['submit']))

{
 

$file_type = $_FILES['file']['type'];

$file_name = $_FILES['file']['name'];
 
 

$file_ext = strtolower(substr($file_name,strrpos($file_name,".")));

$FILE_MIMES = array('application/dbase','application/x-dbase','application/dbf','application/x-dbf','zz-application/zz-winassoc-dbf');

$FILE_EXTS = array('.dbf','.DBF');
 
 

 if (!in_array($file_type, $FILE_MIMES) && !in_array($file_ext, $FILE_EXTS) )

	{

echo "Sorry, $file_name($file_type) is not allowed to be uploaded.";

exit();

	}

$target_path = "uploads/";

$target_path = $target_path . basename( $_FILES['file']['name']);

$_FILES['file']['tmp_name'];

	if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path))

{
 

    echo "The file ".  basename( $_FILES['file']['name']). " has been uploaded";

}

else

{

    echo "There was an error uploading the file, please try again!";

}

  }
 

?>

Open in new window

0
Comment
Question by:sudanshu
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
deresh earned 500 total points
ID: 22719690
do a redirect to the same page after file has been downloaded.
You will lose info message after upload (refresh will be instant), so you may have put it in session to display after redirect.

add this after line 34 ( before the } ):

header("Location: ".$_SERVER['PHP_SELF']);

exit;

Open in new window

0
 

Author Comment

by:sudanshu
ID: 22719825
thanks  it works
0
 
LVL 6

Expert Comment

by:deresh
ID: 22720254
np
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Parts and Products table schema in mysql 6 44
.php tree directory? 5 57
test if query has no results 2 19
Why my select dropdown does not work? 8 27
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now