How do I store an uploaded file in the database? |
[eluser]gtech[/eluser]
I have recently needed to solve this problem as my client wants thier image data to be stored in a database. the key is to use addslashes() and removeslashes() when inserting and retrieving the data in a database. I have posted up what I have done to get it working, to save others head scratching.. my database table contains a mediumblob to store images. In the upload function I store the contents of the uploaded file in a variable called $content and call addslashes($content); so it can be inserted into the database. Code: ... then to display it I use stripslashes() Code: <?php
[eluser]Dan Tdr[/eluser]
hey gtech i would need some help please if you can help me out it would be just perfect.. ok so here`s my problem... i want to upload a file on my server and then put the file name in the database i have the files from the userguide upload file.. i have a do_upload function and 2 files upload_form and upload_success.. now what i want is: after i click the upload button from the upload form the original file name to be stored into the database i saw you accessed it this way : $fileName = $data['upload_data']['orig_name']; now.. it would be hard for you to post all 3 files modifide to upload a file on my server and then ut the file name into the database? i mean.. could you please put all the things together? i can`t seem to figure it out.. and i`ve been trying for abut a week now.. and still not even close thanks, Dan
[eluser]Colin Williams[/eluser]
It just makes more sense to me to store binary data on the file system, especially in a Web development environment. If a client simply said "I want to store images in a database" I wouldn't take that to mean they literally want binary data stored in the database, although I would clarify just in case.
[eluser]Unknown[/eluser]
Some people may also find the PHP function serialize useful for storing the file metadata in a database. That way you can store the whole $this->upload->data() array without throwing away information that may be useful in the future, eg: image sizes, file sizes etc. http://us3.php.net/manual/en/function.serialize.php
[eluser]Franklin2988[/eluser]
Hi everybody I was trying to save images in the database but I get this error Code: A Database Error Occurred I followed gtech example but when I get that error, If you can help me solving this It would be great. |
Welcome Guest, Not a member yet? Register Sign In |