I've been trying to follow a tutorial that let's me insert info into my MySQL database and upload an image to go with it. After much tweaking and pulling of hair, I think I got it to work. Here's my table, called simply "art":
ArtID - Primary Key
Title - VARCHAR(100)
CategoryID - INT
CreditID - INT
Size - VARCHAR(100)
Comments - BLOB
Date - DATE
mimeType - VARCHAR(30),
mimeName - VARCHAR(30)
Now form wise, I think I got everything to insert properly because, after uploading the image, the mimeType and mimeName fields were filled in appropriately with "image/gif" and "GIF Image", respectively. Just in case though, here's the insert part of the code I'm using:
if ($submit)
{
//was a file uploaded?
if (is_uploaded_file($userfile))
{
switch ($userfile_type)
{
case "image/gif";
$mimeName = "GIF Image";
break;
case "image/jpeg";
$mimeName = "JPEG Image";
break;
default:
$mimeName = "Unknown image type";
}
//open the uploaded file
$file = fopen($userfile, "r");
//read the uploaded file
$fileContents = fread($file, filesize($userfile));
//escape special characters in file
$fileContents = Addslashes($fileContents);
}
else
$fileContents = NULL;
$sql="INSERT INTO art
VALUES ('','$Title','$CategoryID','$CreditID','$Size','$Comments','$Date','$userfile_type','$mimeName')";
$result=mysql_query($sql,$db);
echo "<B CLASS=header>Art Submitted!</B><P>\n";
echo "$Title was inserted into the database.<P>\n";
echo "<CENTER><A HREF=$PHP_SELF><B>INDEX</B></A></CENTER>\n";
}
Now my problem is uh...how do I display the image? The tutorial didn't really go into that too clearly. Can someone point me in the direction of a better tutorial on image handling with PHP and MySQL or give me a brief demonstration on how to display a MySQL imbedded image?