Page 1 of 1

store display LONGBLOB; mysql

PostPosted: 21. August 2009 09:09
by alicemcline
hi
i am experiencing strange problem while trying to upload images into mysql LONGBLOB field.. only 255 characters are getting stored and displayed and hence, image is not displayed.. :(

Following is code which i am using for storing icon..
Code: Select all
echo 'Updating Icon..<br/>';
$fname = $_FILES['icon']['tmp_name'];
$ftype = $_FILES['icon']['type'];
$fsize = $_FILES['icon']['size'];
                     
$fp = fopen($fname, 'rb');
$data = addslashes(fread($fp, $fsize));
fclose($fp);

mysql_query("update mytable set icontype = '" . $ftype . "', icon = '" . $data . "' where entity = 'myentity';", $con);
if (mysql_errno())
   die (mysql_error());
                     
unlink($fname);


Following is the code i am using for displaying LONGBLOB
Code: Select all
$iconResult = mysql_query("select icon, icontype from mytable where entity= 'myentity';");
$iconRow = mysql_fetch_assoc($iconResult);
header('Content-Type: ' . $iconRow['icontype'] . "\n");
//header('Content-length: ' . strlen($iconRow['icon']) . "\n");
print $iconRow['icon'];


please tell me what mistake i am making, and how to fix this problem..

thanks alot..

Re: store display LONGBLOB; mysql

PostPosted: 21. August 2009 10:46
by alicemcline
any ideas regarding what's wrong? any configuration file?

Re: store display LONGBLOB; mysql

PostPosted: 21. August 2009 13:24
by Wiedmann
Hm, with my own testscript that's working without problems...

only 255 characters are getting stored

Maybe the field "icon" in the table "mytable" in your selected db does not have the type "longblob"? Or you have 255 in "$_FILES['icon']['size']"?

Re: store display LONGBLOB; mysql

PostPosted: 21. August 2009 14:22
by alicemcline
Thanks for the reply & solution Wiedmann.. you are genius.. :)

mistake was in that table, icon was set to varchar(255) (hmm i mistakenly editted icon instead of another field last time..)