Monday, 8 June 2015

UPLOAD -IMAGE -SCRIPT IN PHP & DISPLAY

(1)first write code for "uploadform.html" file:

<form  action="upload.php"     method="post"     enctype="multipart/form-data">
<input type="file"    name="file"   id="file" >
<input type=submit  name="upload"   value="upload">
</form>

(2)write code for  "upload.php"  file:
<?php

if(isset($_POST["upload"]))
{

$file=$_FILES["file"]["name"];

move_uploaded_file($_FILES["file"]["tmp_name"],"upload/".$_FILES["file"]["name"]);

$con=mysql_connect("localhost","root","");

mysql_select_db("data",$con);

$sql="insert into upload(file) values ('$file')";

mysql_query($sql);

}

?>

(3)write  code to  display images which is uploaded  "display.php"  file :

<?php

$con=mysql_connect("localhost","root","");

mysql_select_db("data",$con);

$sql="select * from  upload";

$result=mysql_query($sql);

while($row=mysql_fetch_array($result))
{

echo $row['file'];
echo '<img src=upload/'.$row['file'].'  heigth=200  width=300>';

}

?>

No comments:

Post a Comment