Jump to content

[SOLVED] Displaying BLOB file - not working?


mr_pablo

Recommended Posts

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.