tags:

views:

492

answers:

4

I need a php code and sql code that will let someone upload an image to a database. The only thing I can find is very glictchy and not accepted by some browsers. Any ideas?

+2  A: 

If I understood correctly, you want to upload image files (or any files) via browser to the server and save them in the database. If that is the case, read this:

http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/uploading-files-to-mysql-database.aspx

Bruno Rothgiesser
The tutorial code doesn't sanitize $fileName and $fileType before using them in the INSERT statement. Both contain data sent by the client that can include "harmful" characters.addslashes() may be sufficient for connection_cahrset=latin1 but is not for other charsets. See http://shiflett.org/blog/2006/jan/addslashes-versus-mysql-real-escape-string , http://ilia.ws/archives/103-mysql_real_escape_string-versus-Prepared-Statements.html and http://php.net/function.mysql-set-charset
VolkerK
Yes. That tutorial is a good starting point for understanding the fundamentals of the steps involved in file upload to a database with PHP. In the actual production code, some security checks would have to be added, e.g. file type and file size.
Bruno Rothgiesser
+1  A: 

There are likely lots of available tutorials online to show you how to do this (you might take a look at this one: http://www.codewalkers.com/c/a/Database-Articles/Storing-Images-in-Database/).

I think that this is not the most efficient way to handle images, however. You might consider writing them to a folder and simply keep the name of the file and its location in the database. This stackoverflow question might help: http://stackoverflow.com/questions/450876/upload-image-to-server-using-php-store-file-name-in-a-mysql-database-with-other

Abinadi
A: 

NEVER store images in the database. NEVER EVER EVER EVER. There are tons of other questions posted here about it that you may want to ready up on.

Always store directly on filesystem, and store the image URL of the file in the database.

Danny
A: 

how image upload in maktba database of books and also how we show it