By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,349 Members | 1,353 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,349 IT Pros & Developers. It's quick & easy.

PHP remove previous output

P: 1
Hi all!
I'm newbie on php. On the web site i'm developing, i have encoutered a problem that i can't resolve.
I have a script that makes the file upload, and then, based on the upload, it displays a message on another .php file. (success, or invalid file). When a user uploads a file, and a "success" message is displayed, when the same user uploads another file and it is displayd a error message, this error message appears under the previous "echo" success message...
I want that when a user makes a success upload, if the next upload displays an error message, that message appears in the same page as the previous one, but without the previous "success" message that appeared.

Here is my upload.php and success.php scripts:
########upload.php##############
session_start();
$temp_upload="temp_upload/";
/*$server="localhost";
$user="root";
$password="";
$db="teste";
$con=mysql_connect($server, $user, $password);
if(!$con)
{
die('Could not connect:'.mysql_error());
}
else{
$descricao=$_POST["description"];
$query="INSERT INTO files(description) VALUES('$description')";
mysql_query($query);
mysql_close();
*/
$filename=$HTTP_POST_FILES['userfile']['name'];
$filetype=$HTTP_POST_FILES['userfile']['type'];
$filesize=$HTTP_POST_FILES['userfile']['size'];

if ( ($filetype=="application/msword") || ($filetype=="text/plain") || ($filetype=="application/pdf") && ($filesize<1000000)) {
if ( (move_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'], "temp_upload/".$HTTP_POST_FILES['userfile']['name']))){
$_SESSION["upload"]=1;
header("Location:success.php");
}
else{
$_SESSION["upload"]=2;
header("Location:success.php");
}
}
else{
$_SESSION["upload"]=3;
header("Location:success.php");
}
?>
######################

#######success.php###############
<?php
session_start();
echo"Sessão Iniciada como: ".$_SESSION["login"];
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<p></p>
<p></p>
<p></p>
<label><b>FILE UPLOAD</b></label>
<p></p>
<table>
<form id="form" name="form" method="post" action="upload.php" enctype="multipart/form-data">
<tr>
<td><label for="description">document description</label></td>

<td><input name="description" type="text" id="description"/></td>
</tr>
<tr><td><label for="file">Choose File</label><td><input name="userfile" type="file"></td>
<tr><td></td>
<td><input type="submit" value="Enviar">
</td>
</tr>

</form>
</table>

<label><?php if(($_SESSION["upload_success"]=1))
echo"<b>File was succefully uploaded</b>";
if(($_SESSION["upload_success"]=2))
echo"<b>Error while uploading the file</b>";
if(($_SESSION["upload_success"]=3))
echo"<b>Invalid File</b>";

?>

</label>



</body>
</html>

######################
May 2 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.