1

how to add image file/s to mysql table.I am a programmer I am using php and mysql.

1

3 Answers 3

1

You shouldn't add the image itself for websites. You upload the image to the server and then save the path into the database. You should be able to then output the path of the file to HTML.

Sign up to request clarification or add additional context in comments.

Comments

1

You need to use blob (or mediumblob or longblob depending on the maximum size of images you want to support) data type for storing binary data.

Before inserting, be sure to escape special characters in the binary image data.

 $img_data =mysql_real_escape_string(file_get_contents($filename));

Comments

0

I usually store the url of the image file rather than the file itself (not too sure how you would do that anyway). I recommend storing the url and using

9 Comments

there are advantages and disadvantages to both approaches.
@JP19 Name some advantages to the BLOB approach.
Eliminate disk I/O. Faster access because of caching (I know, there exist super duper fast hard disks - but my VPS disk I/O is modest). DB storage is especially suited for favicons & thumbnails. Managing permissions is also easier (you just have to bother about DB users/perms, not file system folders). Also - I accept that the average user doesn't need DB storage of images. But there are cases where people may want it - its not as redundant as you feel imo!
@JP19 With the exception of "managing permissions", that's all simply untrue. Read stackoverflow.com/questions/3748/…
@middaparka: It is true that my VPS disk I/O is modest :) (read slow). I am also using APC cache, which makes storing favicons/thumbnails in DB even better for me.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.