DATABASE-FILE-UPLOAD-DOWNLOAD.PHP

Have any of your database driven sites been rendered useless because of of lost images? Keeping them in the database is a solution to that problem. Downloads and images are often part of a website's content: If a website's content is to be derived from a database, then so should these. Although it does double the site's disk space requirements, such an approach helps ensure a truer independence of the front-end and business logic of a site from the back-end.

db_upload_file() stores a file in a database table. Make sure that the column data type is big enough for the files you will be storing. db_download_file() retrieves a file from the database and places it in the same path as the script calling it, and returns the relative URL. If the file does not exist in the database, it returns an empty string.