Home » Forum
NoNumber!

Joomla!® Websites & Extensions
development  -  support  -  consultancy

I try to respond within 48 hours (excluding weekends).
If I haven't responded by then, feel free to post a reminder or bug me via email.

My last reply was: 3 Hours, 16 Minutes ago.

Welcome, Guest
Please Login or Register.    Lost Password?

Get garbage characters - jpg from MySQL Blob
(1 viewing) (1) Guest
Go to bottomPage: 1
TOPIC: Get garbage characters - jpg from MySQL Blob
#7837
Get garbage characters - jpg from MySQL Blob 1 Year, 11 Months ago  
Hello Peter,
I did search the forum. And I have spent probaby 40 hours trying to figure this out.

The code piece below is just a sample test code that will work anywhere. All you need to do is put an example.jpg on your directory and put in the username/password/testdatabase names.

I take a simple code piece (see below) and run it as a separate .php file independent of Sourcerer and Joomla and it displays the .jpg image from the MySQL blob field.

But, if I take the same exact code and put it inside Sourcerer inside of Joomla, I get garbage characters "����JFIF``��C   " rather than the image. Exact same code.

I suspect there is something very simple I am missing. If you could take a quick glance, you would make me a very happy person.

Code:
error_reporting(E_ALL);
$my_table = 'imageMySQL';
$my_image = 'example.jpg';
$my_server = 'localhost';
$my_user = 'histor16_jcagney';
$my_pwd = 'Cag11ney';
$my_name = 'histor16_Someone';
$my_link = mysql_connect($my_server, $my_user, $my_pwd)
or exit('Could not connect (' . mysql_errno() . '): ' . mysql_error());
$my = mysql_select_db($my_name, $my_link)
or exit('Could not select database (' . mysql_errno() . '): ' . mysql_error());
$image = file_get_contents("$my_image");
mysql_query("DROP TABLE IF EXISTS $my_table");
mysql_query("CREATE TABLE $my_table (image MEDIUMblob)");
mysql_query("INSERT INTO $my_table (image) VALUES ('".addslashes($image)."')");
$row = mysql_fetch_array(mysql_query("SELECT image FROM $my_table"));
mysql_query("DROP TABLE IF EXISTS $my_table");
header("Content-type: image/jpg");
print $row['image'];
james cagney
Posts: 2
User OfflineClick here to see the profile of this user
The administrator has disabled public write access.
 
#7845
Re: Get garbage characters - jpg from MySQL Blob 1 Year, 11 Months ago  
try to put an exit; at the end.
This will stop Joomla from rendereing the rest of the page and overruling your header info. Joomla, by default renders a page as html, not as an image.
Peter van Westen
Admin
Posts: 9169
User Online NowClick here to see the profile of this user
The administrator has disabled public write access.
Need to contact me directly? Go to my contact page.
If you use any NoNumber! extensions, please post a rating and a review at the Joomla! Extensions Directory.
Are you happy with the support? Please consider buying a License Code to help me to continue development and support.
 
#7882
Re:Get garbage characters - jpg from MySQL Blob 1 Year, 11 Months ago  
Thank you. I appreciate the reply. But the exit just threw me right out of Joomla. I am going to conclude that there is no direct way. I believe I will have to output the blob to a file and then display that through an echo image or pop out of PHP and do a direct image.
james cagney
Posts: 2
User OfflineClick here to see the profile of this user
The administrator has disabled public write access.
 
#7883
Re:Get garbage characters - jpg from MySQL Blob 1 Year, 11 Months ago  
Oh, you are actuall trying to show an image in your joomla setup?!
You can't do it that way!

Yeah, you should have a separate image php file that you can then place in your content via a normal img tag, like:
<img src="http://www.mysite.com/dynamic_image.php?myvar=whatever" />
Peter van Westen
Admin
Posts: 9169
User Online NowClick here to see the profile of this user
The administrator has disabled public write access.
Need to contact me directly? Go to my contact page.
If you use any NoNumber! extensions, please post a rating and a review at the Joomla! Extensions Directory.
Are you happy with the support? Please consider buying a License Code to help me to continue development and support.
 
Go to topPage: 1
Moderators: Peter van Westen
Open Source Training | Online Joomla! Training and Support
MaxCDN | Content Delivery Network | Accelerate your site to the max
hosting joomla