Storing images in database using active record |
[eluser]Unknown[/eluser]
Hello! I have a problem storing an image into database using the active record feature of CodeIgniter. I upload the image from a form, and store the file. And the file is ok in the filesystem. Then, I try to save the image as a field (BLOB type) on a record of the database. The record is saved correctly, but when I check the BLOB content of the recently added file, I see some values are escaped. For example, using HexEdit, a have this results: Correct file: 89 50 4E 47 0D 0A 1A 0A 00 00 00 0D 49 48 44 52 .PNG........|HDR Incorrect file: 89 50 4E 47 0D 0A 1A 0A 5C 30 5C 30 5C 30 0D 49 48 44 52 .PNG....\0\0\0.|HDR The method (in the controller) I'm using to generate the file: Code: function _do_upload( $form_field, $types, $max_size = '', $max_width = '', $max_height = '' ) The method to generate the record (extract): Code: $cover = $this->_do_upload( 'cover', 'gif|jpg|png', '1024', '480', '640' ); And the method from the model to store the book: Code: function save( $libro ) How can I prevent escaping the binary data? Thank you!
[eluser]InsiteFX[/eluser]
It is bad practice to save images into the database! Just save the filename into the database. InsiteFX
[eluser]Jônatan fróes[/eluser]
Active Record Class auto scape querys, so you'll have to write manually.
[eluser]Bart v B[/eluser]
i agree with InsiteFX, bad idea to put images into a database. A better practice is to put the image name into your database. Also much easyer.
[eluser]Jônatan fróes[/eluser]
[quote author="Bart v B" date="1287515752"]i agree with InsiteFX, bad idea to put images into a database. A better practice is to put the image name into your database. Also much easyer. [/quote] I also agree, but sometimes its not possible...
[eluser]Bart v B[/eluser]
[quote author="Jônatan fróes" date="1287519696"][quote author="Bart v B" date="1287515752"]i agree with InsiteFX, bad idea to put images into a database. A better practice is to put the image name into your database. Also much easyer. [/quote] I also agree, but sometimes its not possible...[/quote] What's not possible? store the image names into a database? Or am i reading your reply wrong?
[eluser]Jônatan fróes[/eluser]
[quote author="Bart v B" date="1287522569"][quote author="Jônatan fróes" date="1287519696"][quote author="Bart v B" date="1287515752"]i agree with InsiteFX, bad idea to put images into a database. A better practice is to put the image name into your database. Also much easyer. [/quote] I also agree, but sometimes its not possible...[/quote] What's not possible? store the image names into a database? Or am i reading your reply wrong?[/quote] of course its possible store the image names into a db, but in some projects its necessary to save the image as blob...
[eluser]Bart v B[/eluser]
[quote author="Jônatan fróes" date="1287524476"][quote author="Bart v B" date="1287522569"][quote author="Jônatan fróes" date="1287519696"][quote author="Bart v B" date="1287515752"]i agree with InsiteFX, bad idea to put images into a database. A better practice is to put the image name into your database. Also much easyer. [/quote] I also agree, but sometimes its not possible...[/quote] What's not possible? store the image names into a database? Or am i reading your reply wrong?[/quote] of course its possible store the image names into a db, but in some projects its necessary to save the image as blob...[/quote] I can not imagine any kind of project/application you need to store images into a database. First of all it's a big opperation for a database to fetch the data, and second a database is not designed for that kind of operations (in my opionion ofcourse). If you are affraid that they steal your images, then you beter can not put it online i think. But maybe you can explain some more why there are applications/projects that need to?
[eluser]Jônatan fróes[/eluser]
[quote author="Bart v B" date="1287526376"][quote author="Jônatan fróes" date="1287524476"][quote author="Bart v B" date="1287522569"][quote author="Jônatan fróes" date="1287519696"][quote author="Bart v B" date="1287515752"]i agree with InsiteFX, bad idea to put images into a database. A better practice is to put the image name into your database. Also much easyer. [/quote] I also agree, but sometimes its not possible...[/quote] What's not possible? store the image names into a database? Or am i reading your reply wrong?[/quote] of course its possible store the image names into a db, but in some projects its necessary to save the image as blob...[/quote] I can not imagine any kind of project/application you need to store images into a database. First of all it's a big opperation for a database to fetch the data, and second a database is not designed for that kind of operations (in my opionion ofcourse). If you are affraid that they steal your images, then you beter can not put it online i think. But maybe you can explain some more why there are applications/projects that need to?[/quote] some month ago I worked in a web module for an delphi/firebird app where all images was storage in blob format (and I had to keep it)... sorry for my bad english
[eluser]InsiteFX[/eluser]
If you must do it read this! MySQL Storing Images in Database Table InsiteFX |
Welcome Guest, Not a member yet? Register Sign In |