用新图像更新现有图像

时间:2012-09-09 15:17:15

标签: php mysql css html5

我是php的新手,我想要更新徽标,我的意思是我要上传一个图像文件,我想用logo.png替换,并在我的网页上显示为徽标,到目前为止的代码正在上传一个图像并将图像保存在文件夹中,但没有用新的替换exixting图像,请帮我解决这个问题,谢谢

这是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");

 }
?>

这是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);
?>

1 个答案:

答案 0 :(得分:1)

查看 PHP File Upload Tutorial 。您可以使用logo.png作为文件名。