storing files in a database
Moderator: General Moderators
storing files in a database
does anyone know how i might go about doing this. ive seen another post that was relevant to the same thing but how would i actually go about doing it....does anyone know where i can possibly find some step by step info on this?
- darodesign
- Forum Newbie
- Posts: 19
- Joined: Mon Aug 28, 2006 8:58 am
- Location: Berlin
- Contact:
If you use MySql select teh field type BLOB,
after that you can INSERT an complete File to the Database.
More information you can get on http://www.mysql.com
Read the Docs, for detailed informations!
An other way is to open the File and copy the content, and insert it into the Database.
But this works only for Text Files.
after that you can INSERT an complete File to the Database.
More information you can get on http://www.mysql.com
Read the Docs, for detailed informations!
An other way is to open the File and copy the content, and insert it into the Database.
But this works only for Text Files.
- darodesign
- Forum Newbie
- Posts: 19
- Joined: Mon Aug 28, 2006 8:58 am
- Location: Berlin
- Contact:
Storing files in the database is definitely cool. Ultimately though, it's better to store the files in the filesystem like ~Oren said. If you're worried about security, you can always keep the files out of the web root & use a PHP file to serve up the file.
With that said, you can store pretty much anything you want in a database blob field. You need to send the right headers along with the binary data though, or you'll just get gibberish:
That snippet will successfully output an image.
I believe BLOB fields only hold 1.6MB of data though, so if you're going bigger than that, look at MEDIUMBLOB. BLOB stands for Binary Large OBject - basically you're just storing the binary data of ... something.
With that said, you can store pretty much anything you want in a database blob field. You need to send the right headers along with the binary data though, or you'll just get gibberish:
Code: Select all
$image_data;//let's say this contains the binary data that is your JPG image
header("Content-type: image/jpeg");
echo $image_data;I believe BLOB fields only hold 1.6MB of data though, so if you're going bigger than that, look at MEDIUMBLOB. BLOB stands for Binary Large OBject - basically you're just storing the binary data of ... something.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.