php - Why images from mysql database displayed as broken? -


i have stored image blob data type in mysql database, when image retrieved showed broken image. i'm not sure wrong following code:

<?php $msg = ''; if (isset($_post['upload'])){     $image = $_files['image']['tmp_name'];     $img = file_get_contents($image);     $con = mysqli_connect('localhost','root','','mydatabase') or die('unable connect');     $sql = "insert info (image) values(?)";      $stmt = mysqli_prepare($con,$sql);      mysqli_stmt_bind_param($stmt, "s",$img);     mysqli_stmt_execute($stmt);      $affected = mysqli_stmt_affected_rows($stmt);     if($affected==1){         $msg = 'done';     }else{         $msg = 'failed';     }         mysqli_close($con); } if (isset($_post['show'])){ $id=2; $con= mysqli_connect("localhost","root","","mydatabase"); $sql = "select * info id = $id"; $sth = $con->query($sql); $result=mysqli_fetch_array($sth); echo '<img src="data:image/jpeg;base64,'.base64_encode( $result['image'] ).'"/>'; mysqli_close($con); }     ?> 

i found mistake. changed data type of image filed database longblob instead of blob.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -