Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...

When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Storing Images In MySQL

Article Comments (31 total)

Displaying article comments 11 to 20 of 31
Jonathan Porta, 5 February 2009
Another thing I noticed was that the line "is_uploaded_file($_FILES['userfile']['tmp_name']" fails to validate whether a file was uploaded because it fails to check where the file information is tored in the $_FILES array. If you remove the [] from the name of the 'userfile' form field, this will work fine. If you are confused, do a print_r() dump on the $_FILES array and you will see that the information for the uploaded file is buried deeper than you may have thought. Not trying to pull apart your tutorial, but I pulled this code because I didn't want to rewrite it, lol. Great tutorial, though. :)

Jonathan Porta, 5 February 2009
Perhaps I am missing something, but it seems that $maxsize never gets defined. Look at the lines "// check the file is less than the maximum file size if($_FILES['userfile']['size']

Eric Mann, 6 January 2009
I love this method for storing images, but I have two questions: 1) Can this process be easily modified to store other, non-image file types? 2) I have a problem with uploading where the bottom portions of large images is cut off. I've tried modifying the upload_max_filesize value in my PHP config files, but this doesn't fix the problem. What other settings should I look at?

Gentlemike2, 5 January 2009
For smaller websites, this seems like an excellent way to manage user images. One application of this concept might be to have the view.php file display a random image for CAPTCHAs. Inclusion of a short term (15 seconds) authorization code as a GET variable on the end of the uri of view.php would keep unwanted advertisers from browsing your entire CAPTCHA library. The script that generates the html (or xhtml or whatever) where the CAPTCHA is called would generate the auth code, enter it in the database, and set an expire for it. There would be no way to sit and reload view.php over and over until you had some handle on all the CAPTCHA images. Without a valid auth code on the end of the uri, a plain grey image might be substituted for the random image that would otherwise be chosen. I am going to have to expirement with this.

Matthew, 8 November 2008
Using mod_rewrites (apache) to map filename requests to a php file can make it so that clients access images as individual files, and the server stores it in any way you wish. Almost all the work for this is done anyway if you want to restrict or grant access to images or other files depending on the credentials of the client. In these cases you need to intercept the client request for images anyway.

T0aD, 13 September 2008
I just wanted to react on some points: # Ease of backup I'm not sure it's very fast and easy to dump / export a table with a lot of binary data in it.. compared to moving / compressing a file. # Saving of Inodes That's for sure, one myisam table will use 3 inodes and still can contain what could have been 3 millions inodes # Easy categorisation I don't agree with that, that would be the same if the file was stored on the filesystem and its metadata would be saved on MySQL. This has nothing to do with 'Storing images in MySQL'. Plus you would probably want to separate the table with metadata and the one with data (to optimize the searches).

Donald E King, 11 September 2008
Within form is a field "userfile[]". What is the purpose of the square brackets?

M, 20 April 8172
I believe the layout is seeming a bit backwards but its just in the order of naming the files, like with view.php and then describing a function calling to view.php when I thought i was working on reading how to edit it. This loading that in two files will slow the db down anyway and muh more so than doing select * from xtabl where id = N Now in effect you do ... select id, imgdata, and so on from imgtable then you go to view.php and do another select from... why even bother closing the table and database in between when you where just there?

jagadeesh, 18 August 2008
its easy to understand but difficult to implement the code.. but its fine

kannan, 20 April 3747
excellent info, thanks. pls publish more articles like this
Submit a Comment
Use the following form to submit a comment for this article. You can include any required code snippets, which we will format and highlight accordingly.

Note: Before your comment appears on PhpRiot, it must be manually approved. The email address field is optional. If you choose to include it, it will be displayed obfuscated to protect it from spammers.

In This Article

Article History

Apr 20, 9804
Initial article version
Jan 18, 2008
Updated listing 5 to not include non-existent conf.php