| |||||||||||
| |||||||||||
PHP - processing images as mySQL Blobs Posted by sisko (sisko), 4 October 2007 Firstly, I upload images via a simple form uploading facility. The image's byte data is then saved to mysql in a BLOB field.Secondly, I try reading that information back and reconstituing the image for displaying on my webpage(s). I need help with this process as I don't know where I am going wrong. This is the function used to load the blob into mysql : [PHP] function test(){ if( move_uploaded_file($_FILES['image']['tmp_name'],"management/test/".$_FILES['image']['name']) ){ echo "<br> File move sucessful!"; echo "<br> File Size : ".filesize("management/test/".$_FILES['image']['name'])."<br>"; }else{ echo "<br> File move Failed!"; } $instr = fopen( "management/test/".$_FILES['image']['name'],"rb" ); $data = addslashes(fread($instr,filesize("management/test/".$_FILES['image']['name']))); echo "<br> ".$data; if( !(mysql_query("insert into gallery (title, ext, data) values ('test', 'jpeg', \"".$data."\")") ) ) { echo "<br> We Have A Problem!"; } } [/PHP] And this is the code to display the image : [PHP] function test2(){ $rs = $this->adodb->execute("SELECT * FROM gallery"); while( $obj = $rs->FetchRow() ) { /*echo "<br> title : ".$obj['title']; echo "<br> ext : ".$obj['ext']; echo "<br> time : ".$obj['image_time']; echo "<br> String lenght : ".strlen($obj['data']); echo "<br> data : ".$obj['data']; echo "<br> ************************************* ";*/ // outputing HTTP headers // header('Content-Length: '.strlen($obj['data'])); header("Content-type: image/".$obj['ext']); // outputing image // echo "<br> checking image output : ".$obj['data']; print( $obj['data'] ); } } [/PHP] When I try executing test2(), All I get is the first couple of byte code characters and nothing else. Posted by admin (Graham Ellis), 4 October 2007 Are you doing ANYTHING else except sending the image out from yor web page that calls function test2? In particular, are you sending out some other content? Posted by sisko (sisko), 4 October 2007 Hi Graham,the answer is no. I'm not sending out any other content. The output simply break a few characters into the byte data. So, image seeing "���JFIF" (quotes not included) and nothingelse as the output to image byte code for an image of 2215 bytes. If I'm doing addslashes on my image data and apache has magic_quotes_gpc set to On, does that represent a problem? I tried setting it to off but it was all the same Posted by sisko (sisko), 4 October 2007 I just thought I'd mention aswell, the webpage is not all clear and exclusively attempting to show the image.It delivers other content not unlike your example webpage Posted by admin (Graham Ellis), 5 October 2007 It looks to me like you might be sending something ahead of the header. I suspect the bits outside the function you have shown us. Have you tried calling up the page with telnet rather than with a browser to see exactly what is generated? Posted by sisko (sisko), 6 October 2007 on 10/05/07 at 23:03:55, Graham Ellis wrote:
Forgive my ignorance but I have no idea how to test the page with telnet. Also, I thought the issue was that the byte date was somehow corrupted? Either in writing it in or reading it out. Posted by admin (Graham Ellis), 6 October 2007 I suspect you may have extra bytes / warning messages coming out of the script - from the bit that's outside the function - which is why I suggested that you (a) show that code and (b) test it away from a browser.Telnet browsing - please excuse the highlighting of the URLs telnet www.somehost.com 80 GET /filename.html HTTP/1.1 host: www.somehost.com <a blank line> ..... This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |