how to store a file to mysql database using php script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
suhail_anwar_khan
Forum Newbie
Posts: 11
Joined: Mon Jan 15, 2007 4:22 pm

how to store a file to mysql database using php script

Post by suhail_anwar_khan »

hi,
please can anyone tell me how can i store a file(ms word, .jpeg, .rtf, .bmp etc.) in MySql database using html form and php script.
Last edited by suhail_anwar_khan on Wed Jan 17, 2007 2:49 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You want to store the file itself in MySQL? (This is rarely recommended.)

http://php.net/features.file-upload
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

It's generally better to store the files themselves in a folder, and place whatever file information you need in the database. Unless you need to store the files in the database, check out http://us3.php.net/features.file-upload
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

8O why do people insist on using databases for file storage?

Use the filesystem if you can, storing the filename in the database. If you're worried about filename collisions use the md5() of the file as it's name in the filesystem.

Otherwise, you'll need to re-create a filesystem in PHP & MySQL. I've done it, but I don't recommend doing it.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

Man... did we all jump on that question! :rofl:
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

I was about to as well, but you guys said all there is to say. 8O
Z3RO21
Forum Contributor
Posts: 130
Joined: Thu Aug 17, 2006 8:59 am

Post by Z3RO21 »

I once had a file system running out of MySQL where all the files were stored in the database. The files were not that large though, but they were encrypted. It was easier to just grab them from the DB, decrypt them, and display, but then again this is before I fully grasped the built in file system functions.
Post Reply