Jump to content

Is it Better to Store Image in DB?


shah_ankitb

Recommended Posts

Hello Friends, Is it better to store images in Database or in Folder?.Storing Images in Database it stores in Binary Form.So will it make my DB more larger.So what is the convinent way to store images. http://www.fornewbie.com/article/php/uploa..._tutorial..html From the above link u can see that how can we store images in DB & Retrieve

Link to comment
Share on other sites

There are many pros/cons to storing the binary information in the database versus keeping the file on a server. As its been stated, each scenario is different. Your database server and software are second to the justification of implementing the functionality. One of the most common "pros" for doing it is the higher level of access security you get which is often combined with the how mobile the application is with everything in the DB. Moving a site from one server or host to another might be easier since its just the code and the database. You also have more control over orphaned files as long as your SQL is in order.Again, as its been said, your application requirements should dictate your decision. The technology these days is pushing performance concerns lower on the list of "cons" - but you'd have to have a god handle on what file sizes you expect to be databased.

Link to comment
Share on other sites

The technology these days is pushing performance concerns lower on the list of "cons" - but you'd have to have a god handle on what file sizes you expect to be databased.
That's a good point, you absolutely need a god handle. That way if anything goes wrong, you just pull the god handle. It's kind of like a panic button, except its a handle.
Link to comment
Share on other sites

as for wether or not its the best way, i left the files on the server and put the urls of the files in the DB

$dir = "whatever_dir/";$files = scandir($dir);foreach(files as $photo) {	if(is_dir($photo) == false && $photo != ".DS_Store") {	   //the .DS_Store part is a mac thing		$photo_url = $dir . $photo;		mysql_query("INSERT INTO photos (photo_url) VALUES ('$photo_url')"); 	}}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...