Jump to content

[SOLVED] reading image files from database??


shadiadiph

Recommended Posts

MM I obviously have no idea about this any pointers please.

 

I have just resized and added a thumbnail to my database and now i am tring to call it from the database on a page to be read and it is just displaying aload of nonsense data??

ÔuK‰ ½¼Žõ*HÂ{tà`àg'$pLúgÂ?µ1—VF!p|¢0@ žƒŒôã=8ÁäŸ7†2Ê8iÔÅâ§í9ɹ&ÚkšêMZÎV÷ŸÆÓÑ·m~j5ò\¦U18¼\'^1n(ûõ[j.ÑI¶µm>k;nôÓâ°Þ'ñÇÙ-¡™·2 v:üăî€Î:“ÛŸ`ð—ìÿ©ê —‚´Jçsd

 

the page is full of it like above??

 

 

This is what I am using to call it.

 

<td>
<?
$query = "SELECT thumbnail FROM uploads where intProductID=$adid"; 
$result = MYSQL_QUERY($query); 
$data = MYSQL_RESULT($result,0,"thumbnail");

?>  
<img src="<?=$data?>" />
</td>


 

 

I can't see this anywhere:

header("Content-type: image/jpeg");

 

Try this code...

<td>
<img src="showpic.php?id=<?=$adid?>" />
</td>

 

Next you'll need a new script, let's say "showpic.php":

<?php
$query = "SELECT thumbnail FROM uploads where intProductID=".$GET['id'];
$data = mysql_fetch_assoc(mysql_query($query));
header("Content-type: image/jpeg");
print $data['thumbnail'];
?> 

 

See how you get on with that.

 

EDIT: Edited the HTML bit - forgot to invoke PHP to send variable to the browser!

If you get a "headers cannot be modified" it's because something has already been sent to the browser.

 

btw, did you see my edit with the HTML?

 

I also sent you a PM.

 

Can you post what you have so far so we can see where we are?

I rely want to no, Why you are using the database for images, as a blob,

 

Dont mean to be rude but adding the image name to a database and then echo it out is so much better.

 

Also to be honest using a blob is so slow then a name format.

 

Even faster way is to add a pic name to the database and then use gd function.

 

 

sorry but blobs are headaches for pictures.

 

you can not do much except show the picture once it there in the database.

 

future redevelopment off the picture is a nightmare.

 

but as a learning purpose it good fun far as it goes my opinion.

hi yesideez thanks I have exactly what you gave me i have tried playing with it but am back to where we started with it.

 

Doesnt display any errors

 

on the html view source it says

 

<img src="showpic.php?id=66" /> its the right id number ??

the showpic.php i have this

<? 
session_start();
error_reporting(7);
require("../global/admin_functions.php");
$query = "SELECT thumbnail FROM uploads where intProductID=".$GET['id'];
$data = mysql_fetch_assoc(mysql_query($query));
header("Content-type: image/jpg");
print $data["thumbnail"];
?>

 

shows the error

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/hmtcompa/public_html/user/showpic.php on line 6

 

Warning: Cannot modify header information - headers already sent by (output started at /home/hmtcompa/public_html/user/showpic.php:6) in /home/hmtcompa/public_html/user/showpic.php on line 7

First make sure you have a table called "uploads" that contains fields called "thumbnail" and "intProductID" (CaSe does matter!)

 

Yes, 66 there is right as long as you're wanting to view product 66.

 

The header is giving you an error message because of the MySQL query error message. Eliminate the query problem and your image should display.

not to be relied on but try what happen.

<?php
ob_start();
session_start();
error_reporting(7);
require("../global/admin_functions.php");
$query = "SELECT thumbnail FROM uploads where intProductID=".$GET['id'];
$data = mysql_fetch_assoc(mysql_query($query));
header("Content-type: image/jpg");
print $data["thumbnail"];
ob_flush();
?>

shadiadiph, try this code with the extra stuff you added removed:

<?php
$query = "SELECT thumbnail FROM uploads where intProductID=".$GET['id'];
$data = mysql_fetch_assoc(mysql_query($query));
header("Content-type: image/jpg");
print $data["thumbnail"];
?>

 

You don't need any of the rest - try it and see.

i am looking at the showpic and testing to see what that produces just tried what you said and it did what i thought

 

Warning: mysql_query() [function.mysql-query]: Access denied for user 'hmtcompa'@'localhost' (using password: NO) in /home/hmtcompa/public_html/user/showpic.php on line 3

 

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/hmtcompa/public_html/user/showpic.php on line 3

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/hmtcompa/public_html/user/showpic.php on line 3

 

Warning: Cannot modify header information - headers already sent by (output started at /home/hmtcompa/public_html/user/showpic.php:3) in /home/hmtcompa/public_html/user/showpic.php on line 4

 

i just tried it with this

 

<?php
require("../global/admin_functions.php");
header("Content-type: image/jpg");
$query = "SELECT thumbnail FROM uploads where intProductID=".$GET['id'];
$data = mysql_fetch_assoc(mysql_query($query));
print $data["thumbnail"];
?>

 

i only get the error

 

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/hmtcompa/public_html/user/showpic.php on line 5

 

i am trying to think what can be used instead of mysql_fetch_assoc???

got it working at last wow took so long here is the html had to be changed to

<img src="showpic.php?adid=<?=$adid?>" />

I had to add a seperate field in the image resize upload to database

mysql_query("UPDATE `uploads` SET `thumbnail`= ( \"".$image."\") ,`thumbnailtype`= ( 'image/jpg' ) WHERE `intProductID`= '$adid' ");

and the php showpic code

 

<?php 
require("../global/admin_functions.php"); 
$query = "SELECT thumbnail,thumbnailtype FROM uploads where intProductID=".$_GET['adid'];

$result = MYSQL_QUERY($query); 
$data = MYSQL_RESULT($result,0,"thumbnail"); 
$type = MYSQL_RESULT($result,0,"thumbnailtype"); 
Header( "Content-type: $type"); 



print $data; 
?> 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.