0

in my page it is not showing images/.. in for images it is showing blank boxes i dont know where i am going wrong ..

   <form action="login.php" method="post" enctype="multipart/form-data">
   <input type="text"
    <br><br><br>
    select image:<input type="file" name="image" size="40" id="image">
              <br><small> must be less than 512kb </small>

    <br><br>         <input type="submit" name="submit" value="submit">  
    </form>

even i dont find any error... please make my correct and telll me why it is not showing any image

   <?php

 if(isset($_POST['submit']))
 {
 if(getimagesize($_FILES['image'] ['tmp_name'])==FALSE)

{ 
    echo "<script> please insert the image </script>";
     exit();
 }

 else
 {
 $image=addslashes($_FILES['image'] ['tmp_name']);
 $name=addslashes($_FILES['image'] ['name']);
 $image= file_get_contents($image);
 $image= base64_encode($image);
 saveimage($name,$image);


 }
}

  displayimage();

  function saveimage($name,$image)
  {
   $con=@mysqli_connect("localhost","root","","work");

   $qry="insert into pics( name, image) values('$name','$image')";

    $result= mysqli_query($con,$qry);

if($result)
{
echo"<br> image uploaded";
}

else
  {
   echo"<br> image not uploaded";
   }

   }

function displayimage()
{
  $con=@mysqli_connect("localhost","root","","work");

  $qry= "select* from pics";

  $result= mysqli_query($con,$qry);

   while($row = mysqli_fetch_array($result))
 {
    echo"<img height=\"250\" width=\"250\" src=\"data:image;base64,\" '.$row[2].' >";
  }
  mysqli_close($con);


 }


 ?>

i am stucked here please help me to get out from here

H. Pauwelyn
  • 11,346
  • 26
  • 71
  • 115

2 Answers2

0

Maybe this helps: How to display Base64 images in HTML?

Can you otherwise provide us the html that is generated?

Maybe you have to provide the type of the file, jpg/png:

Community
  • 1
  • 1
Jim
  • 371
  • 3
  • 16
0

First you have forget to close your

<input type="text"

But still if you manage to store your image in database its fine.

I would like to inform you here as you encoding base64 your image so you expect the final name will be too long, when i mean long means really long. so Make sure your database type for image is much larger that accommodate full name, i suggest to change it to "text type".

one more-thing you miss here to Display your image by base64_encode is, "your image type" in img Tag and also a Row[2] is not appropriate change it to Row[1] or Row['image']

Replace it with

echo"<img height='250' width='250' src='data:image/type of image;base64', '".$row[1]."' >";

if you have different type of images you can save type before you show in any variable and than use that variable instead.

Like

$img_type = 'png or jpg';
echo"<img height='250' width='250' src='data:image/".$img_type.";base64', '".$row[1]."' >";

This should work for you as it do work for me.

php-coder
  • 947
  • 1
  • 12
  • 22
  • Please check my new updated answer. it will work for you. in short change your data type of image to text and change $row parm, – php-coder Aug 04 '15 at 10:15