updating existing image with new image

im new to php and i want to update a logo, i mean i want to upload an image file which i want to be replaced by the logo.png and shown as a logo on my webpage, the code till now is uploading an image and saving the image in the folder but not replacing the exixting image with the new one, olease help me solve this problem, thanku

this is setup.php

<?php include("../includes/config.php"); ?>
<?php
 if ($_SESSION["isadmin"])
{

$con=mysql_connect($dbserver,$dbusername,$dbpassword);
if (!$con) { die('Could not connect: ' . mysql_error()); }

mysql_select_db($dbname, $con);

 $result = mysql_query("SELECT * FROM setup WHERE (id=".$_SESSION["id"].")");
  while($row = mysql_fetch_array($result))
  {
   $title = $row['title'];
   $theme = $row['theme'];
 }
mysql_close($con);
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Admdin Home</title>
<link rel="StyleSheet" href="css/style.css" type="text/css" media="screen">
</head>
<body>
<?php include("includes/header.php"); ?>
<?php include("includes/nav.php"); ?>
<?php include("includes/aside.php"); ?>
<div id="maincontent">

  <div id="breadcrumbs">
    <a href="">Home</a> >
    <a href="">Setup</a> >
    Customization
 </div>
 <h2>Customize</h2>
 <?php
if (isset($_GET["status"]))
{
 if($_GET["status"]==1)
{
echo("<strong>Customization Done!</strong>");
}
if($_GET["status"]==2)
{
 echo("<strong>Customization Error!!</strong>");
}
}

?>
<form method="post"  action="setup-action.php" enctype="multipart/form-data" >
<label>Title Of Your Organization:</label>  <input type="text" name="title" value="<?php    echo $title; ?>" /> <br /> <br />
<label>Select Theme</label>
<select name="theme" value="<?php echo $theme; ?>">
 <option value="Default">Default</option>
<option value="Dark">Dark</option>
<option value="White">White</option>
</select>
 <br /> <br />
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" name="Upload" value="Upload" />
</form>
</div>

</body>
 <?php include("includes/footer.php"); ?>
</html>
<?php
 }
 else
 {
    header("Location: ".$fullpath."login/unauthorized.php");

 }
?>

this is setup-action.php

    <?php include("../includes/config.php");?>
<?php
$target_path = "../graphics/";

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

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
{
   echo "The file ".  basename( $_FILES['uploadedfile']['name']).
 " has been uploaded";
}
else
{
echo "There was an error uploading the file, please try again!";
}
?>
<?php
$title=$_POST["title"];
$theme=$_POST["theme"];
$con=mysql_connect($dbserver,$dbusername,$dbpassword);
if (!$con) { die('Could not connect: ' . mysql_error()); }

mysql_select_db($dbname, $con);
$result=mysql_query("SELECT * FROM setup WHERE id=".$_SESSION['id']);
$num_rows = mysql_num_rows($result);
if ($num_rows > 0)
{
{
mysql_query("UPDATE setup  SET title='".$title."' , theme='".$theme."'WHERE    id=".$_SESSION['id']);
 header("Location:setup.php?status=1");
}
}
else {
 header("Location:setup.php?status=2");
}
mysql_close($con);
?>

Answers


Have a look at PHP File Upload Tutorial. You may use logo.png as the file name.


Need Your Help

Kindle fire HD shows my app in portrait when i am requiring landscape

java android

I have an app that runs in landscape mode. It's supposed to always be in landscape mode, but if I start it on my Kindle Fire HD holding it vertically, the app will briefly try to display in portrait

Passing cursor record to a function

oracle plsql oracle10g sqlplus

I have a stored procedure. I want to call a function from it. Want to pass the retrieved cursor record to the function. how can i pass the retrieved cursor record as function argument and how ca...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.