getimagesize() & MySQL Image Storage (Running functions on contents of variables)

From: Galen (phplist_at_zinkconsulting.com)
Date: 12/07/03


To: php-general@lists.php.net
Date: Sun, 7 Dec 2003 00:38:13 -0800

I'm using a MySQL database to store images as BLOBs. I know how to
handle all the MySQL stuff, it's easy, and really makes keeping track
of files nice an clean. No permissions, no risk of getting things out
of sync, finding stuff is as easy as SQL.

My question is about handling stuff once you pull it out of the
database. When I store images in the database, I currently stash the
format and the resolution in the database, which works but is a bit
messy. I can't find any easy way to run getimagesize on the contents of
a variable, not a file. I could write the image to a file if I needed
to, but that can be slow and rather inelegant, I'd rather store the
values in the DB. Any ideas on how I could use getimagesize or similar
function to determine the format and resolution of the image in a
variable?

I have had a similar problem with ftp uploading. There was no way to
upload the contents of a variable, so I had to write everything to the
disk, kind of annoying when I have 1,000 files. The script wasn't a
very heavily used script nor could the public execute it, but it bugged
me to no end. I think there are some other functions that also only
operate on files and I've fought with them too.

Is there any kind of generic solution for this? Some kind of wrapper I
could use to make a variable act like a reference to a file but
actually be in memory only?

If this seems totally pointless, please tell me. But it seems like
there should be a way for almost any function that runs off a file to
run off the contents of a variable, it's just binary data.

Thanks,
        Galen



Relevant Pages