3

I am trying to upload image using php and save in mysql database that would accept the different extension of it such as bmp, jpeg etc. By using the following codes, some of the uploaded images displayed incomplete.

This is the 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" >
    &nbsp &nbsp
     </form><a href="admin3.php"><button type="button" class="btn btn-primary">Cancel</button></a>
 </tr>

 </table>
 </html>

This is the 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' WHERE No=3";
$qresult = mysql_query($query);
echo "<script>alert('Records Successfully Updated'); location.href='admin3.php';</script>";
?>

This is the getImage.php:

 <?php

 $No = $_GET['id'];
 $link = mysql_connect("localhost", "root", "");
 mysql_select_db("5r");
 $sql = "SELECT images FROM tblMain WHERE No=$No";
 $result = mysql_query("$sql");
 $row = mysql_fetch_assoc($result);
 mysql_close($link);

 header("Content-type: image/jpeg/bmp/png");
 echo $row['images'];
 ?>
11
  • 1) Where is the insert inside db? 2) mysql_* is deprecated, 3) how big of image are we talking about? Commented Nov 19, 2014 at 13:19
  • 2
    I doubt this is valid header("Content-type: image/jpeg/bmp/png"); as per the manual php.net/manual/en/function.image-type-to-mime-type.php - I suggest you look at stackoverflow.com/a/2634072 Commented Nov 19, 2014 at 13:21
  • 1
    I did not used the Insert statement, because I'm trying to update the uploaded image on database. But every time I uploaded an image that has been edited in picasa photo viewer and has an extension of bmp, the image displayed incomplete. Commented Nov 19, 2014 at 13:41
  • You're welcome Rachelle. Commented Nov 19, 2014 at 13:43
  • What is the database type of images Commented Nov 19, 2014 at 14:16

1 Answer 1

2

Change the data type of the images into Long Blob.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.