aishwarya
aishwarya

Reputation:

how to store images in the file system dynamically?

we are creating a website for hotel booking. we need to store a large number of images. we think it would be a better option to store images in the filesystem and store the path in the database. But do we have to manually save them? We are using web services from another website to get the images. is there a way to save the images dynamically in the filesystem??

Upvotes: 1

Views: 1641

Answers (3)

Dimitrios Mistriotis
Dimitrios Mistriotis

Reputation: 2818

I think that you should store both remote (web service) and local (filesystem) location in the database, with initial file system location blank. If a user requests an image for the first time, download it, update the file field and show it. With this concept you will only have images your clients need.

Upvotes: 0

Alex Rodrigues
Alex Rodrigues

Reputation: 2707

You can use PHP's file get contents function or CURL to download all the images you want to the disk or simply refering the foreign image to your clients and you won't need to store them locally on the server.

If you like Python check the Mecanize lib and BeautifulSoup to parse XML if you need.

Storing in disk vs storing in database has it's beneficts. If you need to scale, it's easier and you can always have a lighttpd or a nginx http servers dedicated to images or simply put it out on other server to balance bandwidth.

Upvotes: 2

Christopher
Christopher

Reputation: 9094

It depends on the database, and how you are serving up the images. In general it is better to save the images to disk, depending on how you are delivering them to the client.

Getting the images is usually a matter of some process on the server downloading them from websites and saving them. On many systems you could use wget or curl to download the images and save them.

It also depends on how you are getting the data. If it is some inline binary via XML or something, then you will need to extract that using the features of your application language, and save it to disk.

The mechanics of how to do that vary wildly depending on the implementation language and the hosting operating system.

Upvotes: 1

Related Questions