Image Upload within Same Page display

<html>
<head>
<title>upload_file</title>
</head>
<body>
<center>
<form action="uploadimage.php" method="post" enctype="multipart/form-data"
name="upload">
<table width="300" border="10">
<tr>
<td>Select File</td>
<td><input name="file" type="file" /></td>
</tr>
<tr>
<td colspan="2"><center>
<input name="sub" type="submit" value="upload" />
</center></td>
</tr>
</table>

</form>
</center>
</body>
</html>
<?php
error_reporting(0);
if(isset($_POST['sub']))
{
$name=$_FILES['file']['name'];
$type=$_FILES['file']['type'];
$size=$_FILES['file']['size'];
$tmp=$_FILES['file']['tmp_name'];

if($name=='')
{
echo"<center> <font color='pink'><h2>choose image file first
</h2></font></center>";

exit();
}

if(( $type == "image/jpeg" )||($type=="image/gif")||($type=="image/png"))
{
if($size<=500000)
{
if (file_exists( $_FILES["file"]["name"]))
{
echo"<center> <font color='pink'><h2>File already are there, select another one
<
/h2></font></center>";

exit();
}

move_uploaded_file($tmp,"$name");    
echo"<center> <font color='pink' ><h2>upload completed
</h2
></font><br>".""."<img src=$name height='300'
width='300'> </center>";

echo "File Details"."<br/>";
echo "Name of file:".$name."<br/>";
echo "Size of file in byte:".$size."<br/>";
echo "Type of file:".$type."<br/>";
echo "Location of file:".$tmp."<br/>";
}

else
{
echo"<center> <font color='pink'><h2>File is very large<
/h2></font></center>";                         }

}        
else
{
echo"<center> <font color='pink'><h2> only jpeg,
png, gif supported</h2></font></center>";          
          }


}

?>


Scripts refference

function uploadAndDisplay()
{
if(!isset($_POST['upload']))
{
// your upload form here
}
else
{
// your upload code here
}

// your picture display here

}

Comments

Popular posts from this blog

Forgot password using codeigniter

Facebook Login With Codeigniter

Geofencing Add Marker and Fetch data from database