[GLLUG] Mysql, PHP and Images

Brad Fears brad@mtsdev.com
13 Mar 2003 19:37:56 -0500


There are many arguments for and against storing images as blobs as
opposed to storing just the location of a blob in the file system.  I'm
assuming you really need to store them as blobs.

The process is relatively simple, since you're just working with binary
data.  Setting up your form should be the time consuming part, because
you'll want to verify the file types and possibly resize images before
inserting them.  Once you've got the image from the upload form, you'll
likely want to addslashes() to it to preserve the binary data, and
possibly get the size.

$binary_data = addslashes(fread(fopen($image, "r"), filesize($image)));

Then just do a normal sql insert.

This article may help to get you started:

"File Uploads Made Easy"
http://www.phpbuilder.com/columns/bealers20000904.php3

The concept is the same, but instead of copy()ing the file like the
article instructs, do your database insert.

--Brad Fears


On Thu, 2003-03-13 at 17:02, Ex Fed wrote:
> Has anyone used PHP and Mysql to create a web app that allows users to 
> upload images to a blob field in a MYSQL database?
> 
> I would like to create an app that would allow for this and append a small 
> addition onto the image that includes the submitters name, email and date 
> submitted, and store this in a mysql database table.
> 
> Is this easily doable? I have never used mysql to store images.  Is it easy 
> to read the image back out of the blob field record?
> 
> Lee D.
> 
> 
> 
> 
> 
> _________________________________________________________________
> Protect your PC - get McAfee.com VirusScan Online  
> http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
> 
> _______________________________________________
> linux-user mailing list
> linux-user@egr.msu.edu
> http://www.egr.msu.edu/mailman/listinfo/linux-user