sazzie Posted October 4, 2007 Share Posted October 4, 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 : 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!"; } } And this is the code to display the image : 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'] ); } } When I try executing test2(), All I get is the first couple of byte code characters and nothing else. Quote Link to comment https://forums.phpfreaks.com/topic/71825-php-processing-images-as-mysql-blobs/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.