Image upload creating problems

iam new to php, i am using image upload script of php to update my logo, whenever user choose the image file the existing image file should be replaced by the new upoaded file and should be updated on the screen as well, for this iam using this script but its not doing anything, i mean its nor replacing the image neither putting the new image into the folder... :( please help me get out of this problem, i've been in this problem since months..

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 />
<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");

}
?>

and this is 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);
?>

Answers


See this URL

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

Try this:-

<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!";
}

      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";
 }
 }
 ?>

Need Your Help

Getting address data from Google Maps XML

c# xml xelement

I've extracted some addresses from google maps and they are in an xml file.

How can I generate “migration” DDL from NHibernate mapping files?

nhibernate postgresql continuous-integration ddl

I'm using NHibernate 2 and PostgreSQL in my project. SchemaExport class does a great job generating DDL scheme for database, but it's great until the first application.

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.