Forum Moderators: coopster
I want to take a JPEG file from the user, resize it and stuff it in a MySQL DB (field type LONGBLOB).
I've got the file upload & resizing working properly, and at that point, after executing
imagecopyresampled($image, $contents, 0, 0, 0, 0, $newxsize, $newysize, $orig_x, $orig_y);
to rezize it I can output it to the browser, so I know thats fine.
I then try to put it in the DB by adding slashes: $image = addslashes($image) then passing $image into the SQL query.
Is that right? Am I correctly storing it in the DB?
It works and doesnt return an error but I'm not sure if what's going into the longblob field is actualy valid data!
I'm then trying to use a second script to read it back and show it.
This script insists on returning the following error no matter what I do, yet I cant see a thing wrong with it:
Parse error: parse error, unexpected T_VARIABLE in /home/sites/site116/web/spitoutimage_fullsize.php5 on line 10
This script's contents are as follows. If you can see what I'm doing wrong I'd be very grateful.
<?php
//take a picture_id (PK in campaignpictures table) and spit out the image data if viewable is set to T
//This script should be set as the SRC attribute of the IMG HTML tag
//This is the file edited on 3rd Feb 2005
$picture_id = $_REQUEST['picture_id'];
$connection = mysql_connect ("localhost", "user", "pass");
mysql_select_db (members);
$result = mysql_query("SELECT * FROM campaignpictures WHERE 'picture_id' = '$picture_id'");
if ($row = mysql_fetch_array($result))
{
$data = $row['binary_content'];
$type = $row['type'];
$data = stripslashes($data);
Header("Content-type: '$type'");
ImageJPEG($data);
}
// Close Database Connection
mysql_close($connection);
?>
By the way, $type is set to "image/jpeg"
Thanks
$result = mysql_query("SELECT * FROM campaignpictures WHERE 'picture_id' = '$picture_id'");
You don't want to quote the actual mysql field name, only the value you are looking up. However, that should not produce a T_VARIABLE error. Sorry I couldn't help.
So what is on line 10?
I'm assuming it's $connection = mysql_connect ("localhost", "user", "pass");
Tim
I've got the script to view the image to execute ok, but its saying
Warning: Supplied argument is not a valid Image resource in /home/sites/site116/web/spitoutimage_fullsize.php on line 21
Line 21 is the one that says ImageJPEG($data);
so presumably its not being stored in the database correctly in the firstplace?
BTW thanks for the help you've all given!