If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Hybrid View

Picture File Upload Database PHP

I am trying to add a picture upload for a project that i am currently doing, but whenever i try this it does not display correctly on the page. But if i add the picture using phpMyadmin it displays fine on the webpage. To display the image on the page i am using this code.

So what i'm thinking at the moment is that once the image has been posted to the php page, it then needs to be converted to the base64, which i think is correct, because i use base64 to display a image uploaded directly to the database. And then the base64 code, should then be added to to "INSERT INTO" etc, right? But i just don't actually know how i would actually do this.

My first suggestion would be to not store the actual image in the DB, since it's just a binary file that you are never going to search or sort on. Instead, store in the file system (since it is, in fact, just a file), perhaps generating some sort of unique file name for it (see uniqid(), etc.), then store information about the image (including its file name) in the database. Then your image-serving script just needs to query the DB to get the applicable file name, send an appropriate content-type header() (probably also retrieved from the DB), then do a readfile() on the actual image file.