shadiadiph Posted December 23, 2008 Share Posted December 23, 2008 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 https://forums.phpfreaks.com/topic/138171-solved-reading-image-files-from-database/ Share on other sites More sharing options...
Yesideez Posted December 23, 2008 Share Posted December 23, 2008 http://www.namepros.com/programming/238185-how-to-display-images-mysql-database.html Link to comment https://forums.phpfreaks.com/topic/138171-solved-reading-image-files-from-database/#findComment-722237 Share on other sites More sharing options...
Yesideez Posted December 23, 2008 Share Posted December 23, 2008 Did you check the data was an actual image before you stored it in the database? Link to comment https://forums.phpfreaks.com/topic/138171-solved-reading-image-files-from-database/#findComment-722238 Share on other sites More sharing options...
Yesideez Posted December 23, 2008 Share Posted December 23, 2008 Just found this link while using Google... http://www.wellho.net/mouth/937_Display-an-image-from-a-MySQL-database-in-a-web-page-via-PHP.html From reading down have you set a header to jpeg? Link to comment https://forums.phpfreaks.com/topic/138171-solved-reading-image-files-from-database/#findComment-722242 Share on other sites More sharing options...
shadiadiph Posted December 23, 2008 Author Share Posted December 23, 2008 yes its a jpeg i am just going through what you suggested see if i can solve it Link to comment https://forums.phpfreaks.com/topic/138171-solved-reading-image-files-from-database/#findComment-722243 Share on other sites More sharing options...
Yesideez Posted December 23, 2008 Share Posted December 23, 2008 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 https://forums.phpfreaks.com/topic/138171-solved-reading-image-files-from-database/#findComment-722244 Share on other sites More sharing options...
shadiadiph Posted December 23, 2008 Author Share Posted December 23, 2008 mm thanks but i tried that didn't work i tried that other script from the other site and that didnt work said header had already started even after removing the others :{ Link to comment https://forums.phpfreaks.com/topic/138171-solved-reading-image-files-from-database/#findComment-722247 Share on other sites More sharing options...
shadiadiph Posted December 23, 2008 Author Share Posted December 23, 2008 in the database it isd saved as [bLOB - 32.2 KiB] it was that size after resizing before and saving to a directory so the image is right. Link to comment https://forums.phpfreaks.com/topic/138171-solved-reading-image-files-from-database/#findComment-722250 Share on other sites More sharing options...
Yesideez Posted December 23, 2008 Share Posted December 23, 2008 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? Link to comment https://forums.phpfreaks.com/topic/138171-solved-reading-image-files-from-database/#findComment-722251 Share on other sites More sharing options...
redarrow Posted December 23, 2008 Share Posted December 23, 2008 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 https://forums.phpfreaks.com/topic/138171-solved-reading-image-files-from-database/#findComment-722255 Share on other sites More sharing options...
shadiadiph Posted December 23, 2008 Author Share Posted December 23, 2008 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 ?? Link to comment https://forums.phpfreaks.com/topic/138171-solved-reading-image-files-from-database/#findComment-722269 Share on other sites More sharing options...
shadiadiph Posted December 23, 2008 Author Share Posted December 23, 2008 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 https://forums.phpfreaks.com/topic/138171-solved-reading-image-files-from-database/#findComment-722286 Share on other sites More sharing options...
Yesideez Posted December 23, 2008 Share Posted December 23, 2008 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 https://forums.phpfreaks.com/topic/138171-solved-reading-image-files-from-database/#findComment-722297 Share on other sites More sharing options...
redarrow Posted December 23, 2008 Share Posted December 23, 2008 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 https://forums.phpfreaks.com/topic/138171-solved-reading-image-files-from-database/#findComment-722304 Share on other sites More sharing options...
Yesideez Posted December 23, 2008 Share Posted December 23, 2008 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 https://forums.phpfreaks.com/topic/138171-solved-reading-image-files-from-database/#findComment-722307 Share on other sites More sharing options...
shadiadiph Posted December 23, 2008 Author Share Posted December 23, 2008 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 https://forums.phpfreaks.com/topic/138171-solved-reading-image-files-from-database/#findComment-722319 Share on other sites More sharing options...
Yesideez Posted December 23, 2008 Share Posted December 23, 2008 In the file that calls showpic.php have you set a connection to the database? Don't try and run this new script straight from your browser - use it from your original script. Link to comment https://forums.phpfreaks.com/topic/138171-solved-reading-image-files-from-database/#findComment-722321 Share on other sites More sharing options...
shadiadiph Posted December 23, 2008 Author Share Posted December 23, 2008 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 https://forums.phpfreaks.com/topic/138171-solved-reading-image-files-from-database/#findComment-722327 Share on other sites More sharing options...
shadiadiph Posted December 23, 2008 Author Share Posted December 23, 2008 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 https://forums.phpfreaks.com/topic/138171-solved-reading-image-files-from-database/#findComment-722549 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.