PHP code for image upload and display



PHP File upload Example

In this php tutorial example we do upload image using file upload and display image on same page in img control after uploading image.

PHP code for image upload and display

<html>
<head>
<title>PHP File Upload example</title>
</head>
<body>

<form action="fileupload.php" enctype="multipart/form-data" method="post">
Select image :
<input type="file" name="file"><br/>
<input type="submit" value="Upload" name="Submit1"> <br/>


</form>
<?php
if(isset($_POST['Submit1']))
{ 
$filepath = "images/" . $_FILES["file"]["name"];

if(move_uploaded_file($_FILES["file"]["tmp_name"], $filepath)) 
{
echo "<img src=".$filepath." height=200 width=300 />";
} 
else 
{
echo "Error !!";
}
} 
?>

</body>
</html>

The out put of php example :

PHP Fie Upload Example
PHP Fie Upload Example

3 thoughts on “PHP code for image upload and display

  1. Thank you somuch for giving a fresh code of image upload and display… This really helpful. other site give a lot of information that I couldn’t find the correct code. So, thanks again. Take care.

Leave a Reply

Your email address will not be published. Required fields are marked *