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 1 to 10 of 31
bl0g3rrrr0000, 11 February 2010

I have to agree with Halfasix, this is a pretty ambiguous and poorly validated tutorial, pity as the layout and content is generally very good. its not evident how this series of scripts should be tied together, whether some should be consolidated in a single file or split amongst multiples, in spite of the naming format.

Steve Collette, 26 January 2010

I have uploaded this exact code onto Startlogic's Appache server and still can't get the image file to upload. ("Please submit a file" error) Startlogic tells me the $_server['PHP_SELF'] is the currently executing script. Please advise -- I have been struggling with this for some time. Thanks in Advance Steve

Brian, 24 October 2009

Just to point out a common usage of this technique ... banks storing scanned versions of checks to be shown in online backing UI's. For img galleries, blogs etc it is best to store the file in a traditional manner. Most virtual hosting providers limit db storage and resources. Knowing your environment, resource limits and user base will greatly aid in your decision.

Steve, 30 September 2009

I'm getting the following errors after running listing-5.php : Warning: Unexpected character in input: '\' (ASCII=92) state=1 (line 2) and Parse error: syntax error, unexpected T_STRING (line 2) I've pasted the code directly. Could it be the naming of the function?

greg, 8 July 2009

finally got it all to work, though there appear to be some errors in the code provided. thanks to other tips provided, i've finally got it. after much hunting around, this is the best simplest tutorial available, though not perfect.

Eugen, 13 May 2009

at Richard@Home: Sorry, but "It's still a bad idea" for what kind of applications? My opinion: It's neither a good nor a bad idea, it simply can't be one of the both for general, the decision for one or the other depends on many things like: How big are the images, for what are they used and so on. Would you say that it's better to store many little PNG icons (eg 16x16) in file system? I don't think so... They are about 300 bytes.

Don Evans, 11 March 2009
Well now, I've been over this block so many times, I foget how to do any of it! However, I found this SQL up/down thing very useful and have implemented it and things like it for years. I do believe that this tutorial was better than anything I have seen to date. The argument over File/Db is not very interesting. Some do it one way, some the other. There are times when I do it one way and then the other, for reasons that go beyond this discussion. Let me say that this treatment of the issue was as clear as I have seen. Thanks for it and good luck to all of you. Regards, Don Evans

Linda, 2 March 2009
The upload() function doesn't use exceptions as stated on step 6. It just dies on errors. mysql_real_escape_string() should be used instead of addslashes() Step 6 always retrieve the image with id 0. It is arguable if is_numeric is the right way:

barbu, 20 April 1848
I have copied and pasted the code and the image uploading works fine but i cannot display images.When i echo the $array['image'] in showfile.php it gives Resource id#5

scott, 19 February 2009
Hey Guys, So I just bought the files for this.. Thanks Kevin for providing!... Just need an ounce of guidance here. Should I be able to just upload the files (changing my db info), set up my table, and it all should work? Having some troubles uploading. When I go to "listing-3.php" to upload my image, I hit upload and it just refreshes the page. Is it too late at night? Am I missing something? Thanks! Scott
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