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="t emp_upload/";
/*$server="local host";
$user="root";
$password="";
$db="teste";
$con=mysql_conn ect($server, $user, $password);
if(!$con)
{
die('Could not connect:'.mysql _error());
}
else{
$descricao=$_PO ST["descriptio n"];
$query="INSERT INTO files(descripti on) VALUES('$descri ption')";
mysql_query($qu ery);
mysql_close();
*/
$filename=$HTTP _POST_FILES['userfile']['name'];
$filetype=$HTTP _POST_FILES['userfile']['type'];
$filesize=$HTTP _POST_FILES['userfile']['size'];
if ( ($filetype=="ap plication/msword") || ($filetype=="te xt/plain") || ($filetype=="ap plication/pdf") && ($filesize<1000 000)) {
if ( (move_uploaded_ file($HTTP_POST _FILES['userfile']['tmp_name'], "temp_uploa d/".$HTTP_POST_FI LES['userfile']['name']))){
$_SESSION["upload"]=1;
header("Locatio n:success.php") ;
}
else{
$_SESSION["upload"]=2;
header("Locatio n:success.php") ;
}
}
else{
$_SESSION["upload"]=3;
header("Locatio n:success.php") ;
}
?>
############### #######
#######success. php############ ###
<?php
session_start() ;
echo"Sessão Iniciada como: ".$_SESSION["login"];
?>
<html>
<head>
<title>Untitl ed Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<p></p>
<p></p>
<p></p>
<label><b>FIL E UPLOAD</b></label>
<p></p>
<table>
<form id="form" name="form" method="post" action="upload. php" enctype="multip art/form-data">
<tr>
<td><label for="descriptio n">document description</label></td>
<td><input name="descripti on" type="text" id="description "/></td>
</tr>
<tr><td><labe l for="file">Choo se File</label><td><inpu t 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>
############### #######