Forum Moderators: coopster

Message Too Old, No Replies

images, mysql & t_variable errors

Trying to store & retrieve images

         

bluedalmatian

6:54 pm on Feb 3, 2005 (gmt 0)

10+ Year Member



I've read through loads of so called tutorials on the web about how to do it but I keep running up against the same problems.

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

Birdman

7:23 pm on Feb 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello and welcome to the boards.

It may be the extra quotes in the header:

Header("Content-type: '$type'");

Try:

Header("Content-type: $type");

bluedalmatian

7:33 pm on Feb 3, 2005 (gmt 0)

10+ Year Member



Try:

Header("Content-type: $type")

No, no difference :(

What is a T_VARIABLE anyway :S ?

Birdman

7:53 pm on Feb 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here it is:

mysql_select_db (members);

You didn't quote the db name, it should be:

mysql_select_db ("members");

Sorry, I can't really define T_VARIABLE but it usually happens when a quote or semicolon is left out. Usually the actual error is above the line givin in the error output.

Regards

bluedalmatian

8:11 pm on Feb 3, 2005 (gmt 0)

10+ Year Member



What you say would seem perfectly logical but it still won't work! lol

Birdman

8:22 pm on Feb 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmmm. That's odd! The only other thing I see is this:

$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.

bluedalmatian

8:59 pm on Feb 3, 2005 (gmt 0)

10+ Year Member



Ok, thanks for trying though.

One thing am I putting it in the DB correctly?

Because when I do command line sql select on that table all thats in the binary_contents field is a 1.

Thanks

Timotheos

10:00 pm on Feb 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's a list of tokens... aka 'those T_ things in error messages'
[php.net...]

So what is on line 10?
I'm assuming it's $connection = mysql_connect ("localhost", "user", "pass");

Tim

bluedalmatian

11:17 pm on Feb 3, 2005 (gmt 0)

10+ Year Member



"Here's a list of tokens.."

Thanks for that. Yes you're right about whats on line 10.

Timotheos

6:59 pm on Feb 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Did you find the problem? I can't see anything wrong with it.

bluedalmatian

6:48 pm on Feb 6, 2005 (gmt 0)

10+ Year Member



No I've not found the problem.

I did wonder whether it was the server. I might try it on a different machine and see.

bluedalmatian

8:48 pm on Feb 7, 2005 (gmt 0)

10+ Year Member



OK it would seem that the file is somehow getting corrupted when I copy it to the server.

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!