php - I retrived the BLOB image from MySQL DB but it does not appear on browser -


i inserted image mysql db it's done, image isn't showing. here codes (i've left other blocks php, db connection , basic html tags): (it's learning purpose)

html form:

<label for="user_pic">upload picture:</label>     <input type="file" id="user_pic" name="user_pic" size="30" /> <br /> 

insert.php

$image = $_files[$image_fieldname]; $image_filename = $image['name']; $image_info = getimagesize($image['tmp_name']); $image_mime_type = $image_info['mime']; $image_size = $image['size']; $image_data = file_get_contents($image['tmp_name']);  $insert_image_sql = sprintf("insert images (filename,mime_type,file_size,image_data) values ('%s','%s',%d ,'%s');",mysql_real_escape_string($image_filename),mysql_real_escape_string($image_mime_type),mysql_real_escape_string($image_size),mysql_real_escape_string($image_data));  mysql_query($insert_image_sql) or die(mysql_error()); 

show.php

$image_id = $_request['image_id']; $select_query = sprintf("select * images image_id = %d",$image_id); $result = mysql_query($select_query); $image = mysql_fetch_array($result); header('content-type: ' . $image['mime_type']); header('content-length: ' . $image['file_size']);   echo $image['image_data']; 


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -