View Single Post
Old 01-07-2013, 02:29 AM   PM User | #8
Mehdi72
New Coder

 
Join Date: Jul 2007
Posts: 88
Thanks: 12
Thanked 0 Times in 0 Posts
Mehdi72 is an unknown quantity at this point
Quote:
Originally Posted by felgall View Post
To save an image to a database you should use SQL to read the file into the field like this:

Code:
INSERT INTO databaseimage VALUES ('','$image_name',LOAD_FILE($file))
That way you do away with the PHP code to try to convert it from a file into data that can be inserted into the database. You can also use the SQL DUMPFILE command to write the field from the database directly into a file again. The file in the database should have all of the headers etc included with it (as happens when you use LOAD_FILE) as otherwise the image can be easily broken.

I assume the autoincrement field is there to allow for multiple images with the same name as otherwise the image name could be used as the primary key.

Parse error: syntax error, unexpected T_STRING in imageupload.php on line 36

Code:
if ($image_size==FALSE)
echo "That's not an image.";
else
{
if ($insert = mysql_query("INSERT INTO databaseimage VALUES ('','$image_name',LOAD_FILE($file)))
echo "Problem uploading image";
else
Don't I need to declare the file variable?
Mehdi72 is offline   Reply With Quote