note 41848 added to function.fwrite

From: Date: Fri, 23 Apr 2004 15:52:28 +0000
Subject: note 41848 added to function.fwrite
Groups: php.notes 
Request: Send a blank email to php-notes+get-68675@lists.php.net to get a copy of this message
I hope this spares someone the frusteration of trying to write data (png,gif,jpeg,etc.) into the MySQL blob field. The key here is: addslashes + addcslashes ===== function getImageData($myimg) { $root = 'http://www.foo.com/images/'.$myimg; $hImg = fopen($root,"rb") or die ("Unable to open the img"); echo "Getting img from URL -> ".$root."\n"; $image = ""; while (! feof($hImg) ) { $image .= fread($hImg,1024); } $image = addslashes($image); $image = addcslashes($image,"\0"); return $image; } ===== // Now this SQL INSERT or UPDATE statement will work: $thisimage = getImageData('nameofpic'); $qry = "UPDATE tblmodel SET pic='$thisimage' WHERE ID = ".$line['ID']; mysql_query($qry) or die ("Unable to update record :: $val"); ---- Manual Page -- http://www.php.net/manual/en/function.fwrite.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+41848 Delete -- http://master.php.net/manage/user-notes.php?action=delete+41848&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+41848&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#68675) next »