BCA

WEB PROGRAMMING LAB

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5 PROGRAM 6 PROGRAM 7 PROGRAM 8 PROGRAM 9 PROGRAM 10 PROGRAM 11 PROGRAM 12 PROGRAM 13 PROGRAM 14 PROGRAM 15 . . .

15. Write a program to upload and display an image using PHP.

OUTPUT:
Select image to upload:

PAGE 1: program15startpage.html

 
 

	
 <html>
<body>

<form action="program15endpage.php" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="file" id="file">
    <input type="submit" value="Upload Image" name="submit">
</form>
</body>
</html>


PAGE 1: program15endpage.php

 

 < ? php
 $UPLOADPATH="data/";
try{
	 if ( 0 < $_FILES['file']['error'] ) {
	   echo 'Error: ' . $_FILES['file']['error'] . '<br>';
		 }
		 else {
		move_uploaded_file($_FILES['file']['tmp_name'], $UPLOADPATH .$_FILES['file']['name']);
			}
			$filename=$_FILES['file']['name'];
			$dis=$UPLOADPATH.$filename;
			 if($dis=="")
			  echo "file does not exist";
			  else {
			  echo '<img  src="'.$dis.'"  />';
 				 }
		  		 }catch(exception $e){ 	   
			 	echo "false";
				 }
echo "file uploaded";
?>