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')";

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 = " .
$rv = mysql_query($sql);

if (mysql_num_rows($rv) > 0) {
        header("Content-type: " . $rst["i_img_thum_mime"]);

        echo  $rst["i_img_thum"];

Any help would be GREATLY appriciated.

- craig at periodically dot com

PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to