Tuesday, 11 February 2014

Image Update


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
$id=$_GET['edit_id'];
include("connection/connect.php");
$sql=mysql_query("SELECT * FROM img_up WHERE up_id=$id");
$fetch=mysql_fetch_array($sql);
$name=$fetch['up_name'];
$oldimg=$fetch['up_image'];
echo $oldimg;
?>
<form method="post" enctype="multipart/form-data">
Name:<input type="text" name="name" value="<?php echo $name ;?>" />
Image:<input type="file" name="photo" />
<input type="submit" value="update" name="sub" />
</form>
<?php
include("connection/connect.php");
if(isset($_POST['sub']))
{
$q_name=$_POST['name'];
$q_image=$_FILES['photo'];
if(!empty($q_image['name']))
{
$folder='images/';
unlink($folder.$oldimg);
/*-------Check point for photo--------------*/
if($q_image['type']="images/jpeg"||$q_image['type']="images/jpg"||$q_image['type']="images/png"&&($q_image['size']<1000000))
{
/*create folder for image upload*/



/*Checking whether image name already availiable in the folder*/
if(file_exists($folder.$q_image['name']))
{
$ran_num=rand(0000,9999);
$now_name=$ran_num.$q_image['name'];
}
else
{
$now_name=$q_image['name'];
}
/*Moving the image to the created folder with the unique name*/
move_uploaded_file($q_image['tmp_name'],$folder.$now_name);
}

$upquery=mysql_query("UPDATE img_up SET up_name='$q_name',up_image='$now_name' WHERE up_id=$id");
}
else
{
echo "pls select image";
$upnquery=mysql_query("UPDATE img_up SET up_name='$q_name' WHERE up_id=$id");
}
}
?>
</body>
</html>

No comments:

Post a Comment