SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast mandi_nole's Avatar
    Join Date
    Jun 2001
    Location
    Orlando, FL
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    insert uploaded file into BLOB field

    Ok, I'm new to both PHP and MySQL, but I've been able to write an app that uploads multiple files to the web server and writes the metadata from those files to the database...however, the client wants the actual files themselves inserted into BLOB fields. I've created a separate table for them to be stored so as not to inhibit index and search performance more than necessary, but I'm having trouble figuring out how to insert the file itself into the field. Once it's been uploaded to the server, how do you get it into the database? Any sample code would be helpful.

    Thanks!

    Mandi
    Love ya - mean it!

  2. #2
    SitePoint Member
    Join Date
    Jun 2001
    Location
    UK
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd really consider asking your client not to implement this. MySQL is a wonderous thing, but it does have its limits and unless you want to search the actual binary source of the images (for why i have no idea) it's really a resource waste and with heavy traffic creates unrequired database usuage and overhead.

    -dibby

  3. #3
    SitePoint Enthusiast mandi_nole's Avatar
    Join Date
    Jun 2001
    Location
    Orlando, FL
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    client will not comply...help

    I don't have much of a say in the client implementations - I wasn't in on the initial functional spec talks, unfortunately. I must find a way to actually import these files, themselves, into the BLOB field.

    Can anyone point me in the direction of sample code that does this? I know how to handle the upload, but not the insert.

    Thank you.

    Mandi
    Love ya - mean it!

  4. #4
    SitePoint Enthusiast MarkW78's Avatar
    Join Date
    Mar 2001
    Location
    Wellington, Ohio
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One of my designers coded a client's site to do this. After I realized what he had done I told him to change it so that the pics weren't stored IN the database, just the address of the pics. We're still building the overall site, but here is the code that he had written (which does work) to save the photos into a longblob:

    $data is the file being uploaded

    PHP Code:
    if ($submit) {

    mysql_connect("localhost""user""pass");
    mysql_select_db("dbname");

    $picture addslashes(fread(fopen($data"r"), filesize($data)));

    mysql_query("insert into photos (picture, filename, filesize, filetype) values ('$picture','$data_name','$data_size','$data_type')");

    echo(
    "New Portrait Uploaded:" $data_name);

    I'm not positive it will do what you need it to do, but it's worth a shot. Good luck!
    Mark Wright
    Wrightsites.com - Better Hosting. Better Price.

  5. #5
    SitePoint Enthusiast mandi_nole's Avatar
    Join Date
    Jun 2001
    Location
    Orlando, FL
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    thank you!

    Thanks! That's all I needed! All the documentation merely says that it is possible to do this, but not advisable...however, clients don't always CARE about consequences until they have to maintain the systems themselves!!! Guarantee I'll be rebuilding this again in a month...

    Mandi
    Love ya - mean it!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •