Solved

'PHP_SELF' refresh

Posted on 2008-10-15
3
1,115 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
php hashing methods 3 50
how to block posted data except coming from specific remote ADDR 11 38
PHP substring 3 52
Form submit takes only for one form 23 54
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

739 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