Page 1 of 1

how to store a file to mysql database using php script

Posted: Tue Jan 16, 2007 5:23 pm
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.

Posted: Tue Jan 16, 2007 5:29 pm
by feyd
You want to store the file itself in MySQL? (This is rarely recommended.)

http://php.net/features.file-upload

Posted: Tue Jan 16, 2007 5:29 pm
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

Posted: Tue Jan 16, 2007 5:30 pm
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.

Posted: Tue Jan 16, 2007 5:31 pm
by Kieran Huggins
Man... did we all jump on that question! :rofl:

Posted: Tue Jan 16, 2007 5:39 pm
by Luke
I was about to as well, but you guys said all there is to say. 8O

Posted: Tue Jan 16, 2007 5:43 pm
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.