PDA

View Full Version : Uploading binary data???


josh013
03-04-02, 13:07
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.
JOSH

tcwang66
03-04-02, 21:52
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

josh013
03-08-02, 03:18
Thanks for the idea, finally got it working now.
JOSH

-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
1-title
2-text
3-image (file)
4-orderid

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 "&";
exit;
}

// 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 "&";
exit;
}

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

mysql_query($query);


?>