inserting binary data into a mysql blob field

From: Date: Tue, 25 Feb 2003 03:55:39 +0000
Subject: inserting binary data into a mysql blob field
Groups: php.db 
Request: Send a blank email to php-db+get-25888@lists.php.net to get a copy of this message
I want to be able to insert binary data into a blob field but am having all kinds of problems! I've tried everything twice. I can't get anything to work! Could someone please help me or give me some suggestions? Upload Script: $imgSize1 = $_FILES['userfile1']['size']; $imgSize2 = $_FILES['userfile2']['size']; $image1 = mysql_escape_string(fread(fopen($userfile1, "rb"), $imgSize1)); $image2 = mysql_escape_string(fread(fopen($userfile2, "rb"), $imgSize2)); $sql = "INSERT INTO images (iid, i_img_main, i_img_thum) VALUES (" . $_REQUEST["hdnParent"] . ", '$image1', '$image2')"; mysql_query($sql); I'm using the latest PHP and MySql (as of 24 feb) on Win 2K Server. I'm using the "rb" because for windows, you have to specify binary. I've tried addslashes() instead of mysql_escape_string(), i've tried mysql_real_escape_string(), and i've tryed base64_encode. Data gets entered into the blob fields, but I can't get the image out correctly. I've turned off all magic quotes... all I get is a broken image. Get image script: $sql = "SELECT i_img_thum, i_img_thum_mime FROM images WHERE iid = " . $_REQUEST["id"]; $rv = mysql_query($sql); if (mysql_num_rows($rv) > 0) { header("Content-type: " . $rst["i_img_thum_mime"]); echo $rst["i_img_thum"]; flush(); } Any help would be GREATLY appriciated. - craig at periodically dot com

« previous php.db (#25888) next »