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>


 

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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();
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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???

Link to comment
Share on other sites

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; 
?> 

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.