Wednesday, May 21, 2008

Using PHP MySQL to upload images

In my experience with PHP and MySQL, being a bit of a purist, I have tried to use MySQL to store pictures for a website. This, I discovered, was an exercise in futility. It can be done, but it is FAR more trouble than it is worth. In addition, if you did store the pictures to MySQL (using a BLOB type), modifying it or changing it is even more trouble.

So, the best way it to simply make a directory (or directories), rename the file using a unique name, and put the images in the desired directory. Then, tell MySQL the name of the path and file name. Then, when we need the image, we can query the database for the path, and retrieve the image.

Let's divide it up into steps:
Step 1:

No comments: