Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Storing images and other binary files in MySQL

Status
Not open for further replies.

BenRussell

Programmer
Mar 12, 2001
243
US
I am running an online service that allows users to upload images to my website. Instead of storing the pictures on my website as .jpg or something of that sort, how can I instead store them in a table in my MySQL database? ANd then, how do I retrieve them and display them in the browser?

I am using Perl for the interface. If anyone has any suggestions on how to do this, or any tutorials to point out, that would be great. Thank you.

P.S. I am also interested in storing other types of files also, such as .zip, .exe, .mp3, etc.

- Ben
 
there are some topics already in this subject. search on blob for example. what I know is that it's easier and faster to just work with files instead of storing them in a blob field.

 
I've found it a lot easier to just store the filenames in MySQL and the files on the filesystem, particularly for a website.

If you store the blobs in the database, you need two scripts: one that will fetch data from the database and produce the webpage containing, for example, an appropriately formatted image tag:

<img src=&quot;my_retrieval_script.cgi?name=foo.jpg&quot;>

and a second script that will take in a filename from the URL, fetch the data from MySQL, output the appropriate Content-type header, then stream the data.

Storing just the filenames means you only have to produce and maintain the first script.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top