Forum Moderators: open

Message Too Old, No Replies

Simple modelling issue

mysql modelling upload binary files

         

Awful newbie

11:47 am on May 7, 2007 (gmt 0)

10+ Year Member



Dear friends, my goal is to create a DB where I can store documents and some metadata and make the documents accessible with PHP. I am really new and have realized that I have to build this from scratch. I intend to save the documents as blobs in the MySQL db. Here is my suggestion for DB design:

id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY,
category CHAR(5), (a numeric value)
submitter CHAR(50), (person who uploads document)
doc_url CHAR(50), (url related to document)
dato DATETIME, (date document uploaded)
times_down INT(5), (times document downloaded)
extra CHAR(150), (if I ever need more attributes)
bin_data LONGBLOB, (the four last for the document itself)
filename CHAR(50),
filesize CHAR(50),
filetype CHAR(50)

Would this do it? And -is it possible to get the date from mysql direct instead of posting it? And will it be difficult to make the stored document downloadable, hopefully with an ID or something similar and never the document name in the download url?

phranque

8:27 pm on May 7, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



you can provide the document as a data stream such that there is no "file" available to get directly by http request.
you should at least provide a correct Content-type header and it helps to provide a Content-disposition with a "filename".

you can use the TIMESTAMP column type in mysql to automatically update the column to the current time upon insert or update.
or you can use the NOW() function to valuate the DATETIME column if you prefer.

mcibor

9:07 pm on May 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't recommend this solution - filesystems are better prepared to store files, than db. Instead in DB I would store link to file, description and some more info. If you are unsure to the safety of the files you can make them undownloadable with .htaccess.

Regards
Michal

PS. If you wish otherwise, then headers are a must.

phranque

6:16 am on May 9, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



I don't recommend this solution - filesystems are better prepared to store files, than db.

i completely agree and sorry if i was unclear.
i wasn't suggesting to store the file content in the db, merely to make the file itself inaccessible to the web.

but then i also hadn't noticed this when i originally replied:

bin_data LONGBLOB, (the four last for the document itself)

so like michal said, use the filesystem for files.
lose the longblob, keep the rest.

read up on using TIMESTAMP and the NOW() function to see what works best for you.

your response should be headers and then a stream of data copied from the file.
as long as your script can read the file and the http server can't you should be ok.

Awful newbie

7:58 am on May 10, 2007 (gmt 0)

10+ Year Member



Thank you for your advice! But, how on earth do I make a upload form which stores the metadata in MySQL and the file path in MySQL and the file itself on a protected folder on the server? How do i make a reference to the file from the db? Sorry if I give you headache or LOL, please remember that I am a newbie desperately looking for a solution... :-)

mcibor

12:23 pm on May 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



1. user finds the desired file in db
2. retrieve link
3. send correct headers [php.net]
4. read [php.net] the file
5. echo the content
6. end script

Hope this helps.
If you cannot open the above links, then here you've got them second time:

[php.net...]
[php.net...]

Regards
Michal