1

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

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

1 回答 1

1

看看PHP 文件上传教程。您可以logo.png用作文件名。

于 2012-09-09T15:23:34.817 回答