Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can i display image from database?
    text
    copied!<p>Image can't display from database in php and it's fire such error. When i execute this code such error is occure The image cannot be display beacuse it's contain error.Image is store in mysql datbase and field type is BLOB. IT didn't find any solution to avoid this error. </p> <pre><code>&lt;?php require_once('database/db.class.php'); $objDatabase=new db_class(); $objDatabase-&gt;connect(); $sql="SELECT id,firstname,lastname,sex,email,userimage,ext,city,state,username FROM t_users WHERE username='".$_SESSION['username']."'"; $totalRow=$objDatabase-&gt;select($sql); if($row=$objDatabase-&gt;get_row($totalRow, 'MYSQL_BOTH')) { $userArray=array('id'=&gt;$row['id'],'firstname'=&gt;$row['firstname'],'lastname'=&gt;$row['lastname'],'sex'=&gt;$row['sex'],'email'=&gt;$row['email'],'userimage'=&gt;$row['userimage'],'ext'=&gt;$row['ext'],'city'=&gt;$row['city'],'state'=&gt;$row['state'],'username'=&gt;$row['username']); } ?&gt; &lt;table cellspacing="10px" width="100%"&gt; &lt;tr&gt; &lt;td width="23%" style="vertical-align:top"&gt; &lt;?php header("Content-type: image/{$userArray['ext']}"); header("Content-Length: " . strlen($userArray['userimage'])); echo $userArray['userimage']; ?&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p>Upload Image Code</p> <pre><code>@list(, , $imtype, ) = getimagesize($_FILES['photo']['tmp_name']); // Get image type. // We use @ to omit errors if ($imtype == 3) // cheking image type $ext="png"; // to use it later in HTTP headers elseif ($imtype == 2) $ext="jpeg"; elseif ($imtype == 1) $ext="gif"; else $msg = 'Error: unknown file format'; $img = file_get_contents($_FILES['photo']['tmp_name']); $img = mysql_real_escape_string($img); // Preparing data to be used in MySQL query $data=array('firstname'=&gt;$_REQUEST['firstname'],'lastname'=&gt;$_REQUEST['lastname'],'sex'=&gt;$_REQUEST['gender'],'email'=&gt;$_REQUEST['email'],'userimage'=&gt;$img,'ext'=&gt;$ext,'city'=&gt;$_REQUEST['city'],'state'=&gt;$_REQUEST['state'],'zipcode'=&gt;$_REQUEST['zipcode'],'username'=&gt;$_REQUEST['usernameText'],'password'=&gt;$_REQUEST['passwordText']); $result=$objDatabase-&gt;insert_array('t_users',$data); &lt;input name="photo" type="file" id="photo"&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload