Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2002

    Question Unanswered: Uploading binary data???

    Got another stupid question :
    How do I go about logging an images' URL into the database? I found tons of examples for loading the data into blob datatypes, but these have proven much too slow. I think that I understand the idea behind this; but I need a quick visual. Any help or pointing me in the right direction would be greatly appreciated.

  2. #2
    Join Date
    Feb 2002


    Hi Josh,
    I met the same question as you. I used a simple way to handle this issue. I am not sure it's correct or not, but I hope it can give you a rough idea. I just put the image file name in the column, just like 'image1.jpg', 'image2,jpg' and upload those files in the directory.
    My middleware application( I used JSP or Servlet) will read this 'string',
    find the directory and end up showing the image file...

    Hope that helps,

    TC Wang 03/04/2002

  3. #3
    Join Date
    Feb 2002
    Thanks for the idea, finally got it working now.

    -For anyone interested in how I did it, here's my code (I'm sure someone else could write it better, but this worked for me.)

    My HTML form - conststs of 4 fields
    3-image (file)

    PHP below -


    // createstory.php

    // Attemp connection to MySQL server(localhost)
    $link = @mysql_connect("localhost");

    if ($link == false) {
    echo "&result=Fail&errormsg=";
    echo urlencode("Failed to connect to MySQL server.");
    echo "&";

    // Attemp to select DB
    if (mysql_select_db("*****") == false) {
    echo "&result=Fail&errormsg=";
    echo urlencode("Error selecting database.\n");
    echo urlencode("Error: " . mysql_error($link));
    echo "&";

    //This next chunk copys the selected file
    //And renames the file to the $orderid value

    $imagefile = "images/$orderid.jpg";
    $imagename = "$orderid";
    copy ($upload_image, $imagefile);

    $query = "INSERT INTO lessons VALUES(NULL,";
    $query .= "'" . $title . "',";
    $query .= "'" . $text . "',";
    $query .= "'" . $imagename . "',";
    $query .= "'" . $orderid . "')";


    Last edited by josh013; 03-08-02 at 18:05.

Posting Permissions

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