0

我是 php 新手,我正在使用 php 的图像上传脚本来更新我的徽标,每当用户选择图像文件时,现有图像文件应该被新的上传文件替换并且也应该在屏幕上更新,因为这个 iam 使用这个脚本但它没有做任何事情,我的意思是它也没有替换图像,也没有将新图像放入文件夹...... :(请帮助我摆脱这个问题,几个月以来我一直在这个问题中......

这是 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 />
<label>Choose Your Logo Here</label><input type="file" name="file"/><br /> <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
if(isset($_FILES["file"]))
{
if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] ==   "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg"))
 && ($_FILES["file"]["size"] < 1000000))
 {
 if ($_FILES["file"]["error"] > 0)
  {
     echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
  }

    if (file_exists("../graphics/" . $_FILES["file"]["name"]))
      {
          echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
          move_uploaded_file($_FILES["file"]["name"],
          "../graphics/" . $_FILES["file"]["name"]);
          echo "Stored in: " . "../graphics/" . $_FILES["file"]["name"];
      }
   }
 }
 else
  {
  echo "Invalid file";
  }
 ?>
 <?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

2 回答 2

0

看到这个网址

http://www.tizag.com/phpT/fileupload.php

尝试这个:-

<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>

上传者.php

$target_path = "uploads/";

$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!";
}
于 2012-09-09T10:09:26.410 回答
0
      STEP1: Create file upload.php
     ############### Code

    `<table width="500" border="0" align="center" cellpadding="0" cellspacing="1"           bgcolor="#CCCCCC">
      <tr>
   <form action="upload_ac.php" method="post" enctype="multipart/form-data"       name="form1" id="form1">
  <td>
  <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
  <tr>
 <td><strong>Single File Upload </strong></td>
 </tr>
 <tr>
 <td>Select file 
<input name="ufile" type="file" id="ufile" size="50" /></td>
</tr>
 <tr>
 <td align="center"><input type="submit" name="Submit" value="Upload" /></td>
 </tr>
 </table>
 </td>
 </form>
</tr>
</table>
`
 STEP2: Create file upload_ac.php
  ############### Code



   <?php
  //set where you want to store files
  //in this example we keep file in folder upload 
  //$HTTP_POST_FILES['ufile']['name']; = upload file name
  //for example upload file name cartoon.gif . $path will be upload/cartoon.gif

  $path= "upload/".$HTTP_POST_FILES['ufile']['name'];
  if($ufile !=none)
 {
 if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
 {
 echo "Successful<BR/>"; 

 //$HTTP_POST_FILES['ufile']['name'] = file name
 //$HTTP_POST_FILES['ufile']['size'] = file size
 //$HTTP_POST_FILES['ufile']['type'] = type of file

 echo "File Name :".$HTTP_POST_FILES['ufile']['name']."<BR/>"; 
 echo "File Size :".$HTTP_POST_FILES['ufile']['size']."<BR/>"; 
 echo "File Type :".$HTTP_POST_FILES['ufile']['type']."<BR/>"; 
 echo "<img src=\"$path\" width=\"150\" height=\"150\">";
 }
 else
{
 echo "Error";
 }
 }
 ?>
于 2013-04-08T15:22:17.113 回答