note 41848 deleted from function.fwrite by aidan

From: Date: Thu, 26 Aug 2004 08:58:46 +0000
Subject: note 41848 deleted from function.fwrite by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-75302@lists.php.net to get a copy of this message
Note Submitter: juliank at quidne dot com ---- 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");

« previous php.notes (#75302) next »