Jump to content

image in db or filesystem?


birbal

Recommended Posts

i want to associate a image file for every user. where user will be able to upload a image file. now question is what is the best place to store that image databse or filesystem?i am not sure. may anyone help me on it.thank you.

Link to comment
Share on other sites

There are some advantages of storing the binary image data in the database, mainly pertaining to portability, but for best performance the filesystem is best.

Link to comment
Share on other sites

mainly pertaining to portabilityi did not get that. what do you mean. please elaborate it.if i store it in db then when i will fetch it from db it will slow up the process. is not it?but i want that only image can be accessible via the script (php). you cant get it by URL (i mean not publicaly acessible).

Link to comment
Share on other sites

If you store the images in your database, then it is independent of the filesystem, so even if that changes no change needs to be made to the database.You can always use other mechanisms, such as restrictions on the web server or even storage in a non-web-accessible location, to prevent direct access to the files.

Link to comment
Share on other sites

You can always use other mechanisms, such as restrictions on the web server or even storage in a non-web-accessible location, to prevent direct access to the files.
do you mean by putting file outside of public_html?if yes..then how can i add image file putting it outside of public_html? i thought its not possible to do like this. such as restrictions on the web server how to do that?
Link to comment
Share on other sites

The image is binary data. You can read the file into a string and manipulate it that way.

Link to comment
Share on other sites

thank you synook chokk scintist fmbda for help.by the way i found that there is a option alson in my webhost cpanel for hotlinking.

Link to comment
Share on other sites

do you mean by putting file outside of public_html?if yes..then how can i add image file putting it outside of public_html? i thought its not possible to do like this.
Use a small intermediary script to fetch the image. Something like this (you'll need to modify it a bit). Untested, may have bugs, may cause blindness.
// show_image.php// the image name $img = 'some_image.png';// create full absolute path to actual file object $fn = "/server/path/to/the/$img";// get extension$path_info = pathinfo($fn);$ext = $path_info['extension'];// show only approved filetypesif($ext == 'gif' || $ext == 'jpg' || $ext == 'jpeg' || $ext == 'png'){	// set header 	if($ext == "gif"){header('Content-type: image/gif');}	if($ext == 'jpg'){header('Content-type: image/jpeg');}	if($ext == 'jpeg'){header('Content-type: image/jpeg');}	if($ext == 'png'){header('Content-type: image/png');}		// stream image out to browser	header('Content-transfer-encoding: binary');	header('Content-length: '.filesize($fn));	readfile($fn);}

Use this by calling it from an IMG tage:<img src="show_image.php'>

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...