html - Upload Image using Php and mySQL -
i trying upload image using php , save in mysql database accept different extension of such bmp, jpeg etc. using following codes, of uploaded images displayed incomplete.
this uploadform:
<html> <form method="post" action="updateimage1.php" enctype="multipart/form-data"> <table border=0> <tr> <td><center><img src="getimage.php?id='.$row["no"].'" width=250 height=180/></center><br> <input type="file" name="s4"><br> <input name="update" type="submit" id="update" value="save changes" class="btn btn-primary" >     </form><a href="admin3.php"><button type="button" class="btn btn-primary">cancel</button></a> </tr> </table> </html>
this updateimage1.php:
<?php $s1 = addslashes(file_get_contents($_files['s4']['tmp_name'])); $host="localhost"; $user_name="root"; $database_name="5r"; $db=mysql_connect($host, $user_name,''); if (mysql_error() > "") echo mysql_error() . "<br>"; mysql_select_db($database_name, $db); if (mysql_error() > "") echo mysql_error() . "<br>"; $query = "update tblmain set images='$s1' no=3"; $qresult = mysql_query($query); echo "<script>alert('records updated'); location.href='admin3.php';</script>"; ?>
this getimage.php:
<?php $no = $_get['id']; $link = mysql_connect("localhost", "root", ""); mysql_select_db("5r"); $sql = "select images tblmain no=$no"; $result = mysql_query("$sql"); $row = mysql_fetch_assoc($result); mysql_close($link); header("content-type: image/jpeg/bmp/png"); echo $row['images']; ?>
change data type of images long blob.
Comments
Post a Comment