How to store a php image resource in MySQL?
I have a table that stores images. The two methods (to upload image files to the table) I have used so far (successfully) are LOAD_FILE, and fread to read the image file into a string variable. I can use both of these methods in an sql statement and the image successfully gets sent to the server.
The problem is, with these methods, I have to read the data from a file. My issue now is that I read the image file, and store it as a php image resource. Then I resample it using the GD library. The original image files are like 2-3 MB and I need to store a much lower res pic so I resample it down to like 50 KB. GD works great for that by the way.
So now I have a 50 KB php image resource, but I can't figure out how to insert it into my "insert" statement. I tried casting the image resource to a string, but no dice. The statement returns with no errors, but when I look at the data in phpmyadmin, it is not there.
I have successfully written the new php image resource to a file, then re-read the file, and stored it in MySQL that way, but it seems so un-elegant to read an image file, resample it, write it to file, then read the new file, and then store it in the DB. Surely there must be a way to push the resampled image resource straight to the database? Thanks for any help!
Subject
Written By
Posted
How to store a php image resource in MySQL?
February 01, 2010 09:47AM
February 01, 2010 12:32PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.