Please turn on javascript in your browser to play chess.
Developers Forum

Developers Forum

  1. Subscriber Crowley
    Not Aleister
    27 Sep '04 18:30
    I'm trying to store images in a MySQL database (longblob) type.
    I've got an example snippet code that a friend of mine did a while ago where he did this to store the image file:
    $data=addslashes(fread(fopen($_FILES['fname']['tmp_name'], ), $_FILES['fname']['size']));
    and then there's obviously the sql where he inserted this data into the table.

    He then has a getimg.php file that looks like this:

    // getimg.php
    // Use this page to display images stored in the db
    // usage: <img src=getimg.php?id=132> where id is the
    // corresponding id number of the picture in the db

    if(isset($_REQUEST['id'])) {

    // Include common functions

    // Connect to the database

    // Extract source and filetype from db
    $q=mysql_query(SELECT source,filetype FROM dbimg WHERE id=.$_REQUEST['id']);
    while($r=mysql_fetch_array($q)) {

    // Send headers to browser to indicate type of image
    Header(Content-type: .$type);

    // Send the image source to browser
    echo $source;

    Now my problem is this: The example code works fine and I copied it to use in my site, but it doesn't work for me (on the same server).

    Any ideas??
  2. 29 Sep '04 21:53
    check the include path... are the files in that relative path?
  3. Subscriber Crowley
    Not Aleister
    10 Dec '04 14:10
    OK now I've sorted this out on my development machine. I upload the files to check it - BOOM - no images!

    Here's the problem:
    I made a mediumblob field in a table.
    I take the pic, base64_encode it and then save it in the table.
    To display the picture I base64_decode the field and then just echo it.

    Everything else works, only the images are giving me a headache. The hosting server is Unix - could this be a problem?

    Anyone got any ideas?