Tuesday, 11 February 2014

Image Upload


<!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>

<!-----------FORM--------------------------->


<form method="post" enctype="multipart/form-data">
Name <input type="text" name="name" /><br />
Image <input type="file" name="photo" /><br />
<input type="submit" name="sub"  value="upload"/><br />
</form>
<!------------Getting values fron form------>
<?php
            include("connection/connect.php");
            if(isset($_POST['sub']))
            {
$q_name=$_POST['name'];
$q_image=$_FILES['photo'];
/*-------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*/
$folder='images/';
/*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("INSERT INTO img_up VALUES ('','$q_name','$now_name')");

}


?>
<form method="post">
id:<input type="text" name="myimg" /><br />
<input type="submit"  name="showit"/>
</form>
<?php
include("connection/connect.php");
if(isset($_POST['showit']))
{
$myid=$_POST['myimg'];
$fetch=mysql_query("SELECT * FROM img_up WHERE up_id='$myid'");
$fetchimage=mysql_fetch_array($fetch);

?>
<img src="images/<?php echo $fetchimage['up_image']; ?>" width="132" height="99">
<?php
}
?>
   
    <a href="list_images.php">list</a>
 



</body>
</html>

No comments:

Post a Comment