Storing JPEGS in MySQL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I'd be grateful if someone could offer me some guidance on where I'm going wrong here, I'm sure I'm 99% of the way there...

I want to read in a JPEG from a file upload form (HTML), resize it and store in in a MySQL DB. Then in another script I want to pull it out of the DB and display it.

I've had the first script taking the file, resizing it and spitting it out to the browser OK, so it's the bit to do with the DB thats buggy.


The field in the DB is of type LONGBLOB.

The image is resized like this, and as I say, this far its working fine...
imagecopyresampled($image, $contents, 0, 0, 0, 0, $newxsize, $newysize, $orig_x, $orig_y);


I then try to put it in the DB by passing the variable $image straight into an SQL query. is that correct?

The script executes fine with no errors, and there's something being put in the LONGBLOB field of the DB (Resource ID #3 it says when I look at it).

In another script I try to read it out and display it. This second script will be set to the src attribute of the <IMG> tag.
It works like this:


//connect to db etc..
$result = mysql_query("select * from campaignpictures where 'picture_id' = 1");


	if ($row = mysql_fetch_array($result))
	{
		$data = $row['binary_content'];
		$type = $row['type'];
	}

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


The type field is set correctly by the upload script and is "image/jpeg"

Again this script runs without errors but doesnt produce anything.

Any help would be appreciated.

Thanks
Andrew

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux