mr_pablo Posted March 12, 2009 Share Posted March 12, 2009 I am trying to display an image (later on it will be various file types) by pulling a BLOB string from a MySQL DB, yet I cannot get the image to display, even though my code looks like everyone else I see on the Internet. <? include "includes/config.php"; include "includes/opendb.php"; $id = $_GET['id']; $sql = "SELECT * FROM video_index WHERE video_id = '$id'"; $result = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_array($result); $content = $row['video_content']; header("Content-type: image/jpg"); echo $content; ?> The config and opendb php files are to connect to the DB. If I try going to localhost/file.php?id=1, I get a missing image container that if I right click, does have the correct size, but obviously the image isn't showing. The record definitely exists, so I am totally stumped as to why this isnt working. FYI, the image was uploaded to the LONGBLOB column in my DB using phpmyadmin. Quote Link to comment https://forums.phpfreaks.com/topic/149181-solved-displaying-blob-file-not-working/ Share on other sites More sharing options...
The Little Guy Posted March 12, 2009 Share Posted March 12, 2009 Try making it binary... Don't know if it will work or not, but it is worth a try... <?php include "includes/config.php"; include "includes/opendb.php"; $id = $_GET['id']; $sql = "SELECT * FROM video_index WHERE video_id = '$id'"; $result = mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_array($result); $content = b"{$row['video_content']}"; // I modified this line header("Content-type: image/jpg"); echo $content; ?> Another thing I see, is you have content-type as an image, and $row['video_content']. Is $row['video_content'] an image or video? Quote Link to comment https://forums.phpfreaks.com/topic/149181-solved-displaying-blob-file-not-working/#findComment-783389 Share on other sites More sharing options...
mr_pablo Posted March 12, 2009 Author Share Posted March 12, 2009 Oh yes, my table row is video_content but my test file is simply a jpeg image, as my video files are not ready yet (a friend is editing them somewhat for me) I tried adding the amendment you made, but I still get the same results. Like I said, this code is 100% the same as other image BLOB retrieval code snippets on the 'net, yet mine does not work. Could my storage as LONGBLOB be the problem? or maybe the fact I uploaded the file in phpmyadmin (it has no file type etc assigned to it, unless thats coded in the BLOB) Quote Link to comment https://forums.phpfreaks.com/topic/149181-solved-displaying-blob-file-not-working/#findComment-783409 Share on other sites More sharing options...
The Little Guy Posted March 12, 2009 Share Posted March 12, 2009 do just like what I did... Quote Link to comment https://forums.phpfreaks.com/topic/149181-solved-displaying-blob-file-not-working/#findComment-783411 Share on other sites More sharing options...
mr_pablo Posted March 12, 2009 Author Share Posted March 12, 2009 Sorry, I edited my previous post, your b"{} thing didnt do anything Quote Link to comment https://forums.phpfreaks.com/topic/149181-solved-displaying-blob-file-not-working/#findComment-783415 Share on other sites More sharing options...
The Little Guy Posted March 12, 2009 Share Posted March 12, 2009 OK, go to view the image, then view the page source. Quote Link to comment https://forums.phpfreaks.com/topic/149181-solved-displaying-blob-file-not-working/#findComment-783418 Share on other sites More sharing options...
mr_pablo Posted March 13, 2009 Author Share Posted March 13, 2009 viewing image properties gives the same as before, 0 x 0 dimensions, 0 bit depth, 123 KB (125,662 bytes) (correct file size) but oobv no image being displayed. cannot view page source as its just trying to display an image (as the http header is set to jpeg. i tried googling that b"{} and i cannot find any reference to it... are you sure its even PHP code? Quote Link to comment https://forums.phpfreaks.com/topic/149181-solved-displaying-blob-file-not-working/#findComment-783445 Share on other sites More sharing options...
The Little Guy Posted March 13, 2009 Share Posted March 13, 2009 i tried googling that b"{} and i cannot find any reference to it... are you sure its even PHP code? yes (Check Example #1): is_binary Next I was able to get it using LONGTEXT instead of BLOB Example: http://phpsnips.com/test.php Quote Link to comment https://forums.phpfreaks.com/topic/149181-solved-displaying-blob-file-not-working/#findComment-783473 Share on other sites More sharing options...
mr_pablo Posted March 13, 2009 Author Share Posted March 13, 2009 i really need this to work with LONGBLOB. i set up an upload php script, which works fine, yet still the display script will not show my image, i have tried both image/jpg and image/jpeg but neither work. my data exists in the DB as i ican pull out and view the raw BLOB, yet nothing i try will make it show up. this is getting rather fustrating and i need it fixed today. are there any settings in my PHP.ini or apachae server conf that i could change to try fix this? Quote Link to comment https://forums.phpfreaks.com/topic/149181-solved-displaying-blob-file-not-working/#findComment-783702 Share on other sites More sharing options...
mr_pablo Posted March 13, 2009 Author Share Posted March 13, 2009 SOLVED - Removed the "includes" and put my DB connection data inside the display file. Seems you cannot have includes, even if the included files have nothign but php code. Quote Link to comment https://forums.phpfreaks.com/topic/149181-solved-displaying-blob-file-not-working/#findComment-783716 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.