0

iam phpは初めてですが、phpの画像アップロードスクリプトを使用してロゴを更新しています。ユーザーが画像ファイルを選択するたびに、既存の画像ファイルを新しいupoadedファイルに置き換え、画面上でも更新する必要があります。この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

このURLを参照してください

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>

uploder.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 に答える