Re: scalable web gallery

From: Date: Thu, 10 Jul 2008 08:22:15 +0000
Subject: Re: scalable web gallery
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-276569@lists.php.net to get a copy of this message
O/H paragasu ??????:
i am planning to create a web photo gallery. i know there is a lot available out there, but i really want to create my own. the problem is not about creating the photo gallery. i want it to be scalable. the plan is saving the image metadata in the database and keep the original files in a folder. while it work perfectly, i afraid how many files 1 directory can keep. in 1 year, there going to be more than 1000 photo uploaded or more. sure it bring problem to maintain thus files. when i see big2 website out there like friendster, photobucket. the url for the image change like pic-1.domain.com/images/filename.jpg pic-2.domain.com/images/filename.jpg etc. they seems to put the image in different subdomain. Just wan't to ask anyone who did create a big-big web gallery like this. How did you do it? thanks I never did create a big image gallery but I have worked with uploaded files quite many times. There are many solutions to this so it depends on what you have and what you are willing to do.
A first solution that I can think of is to separate your images in categories. Add a field in the database table that describes the image category and make a directory with the same name. When you query the database you will get the filename of the image (or something like that) and you will get the image from this specific directory. If you so many images that this does not solve this you may add an extra field in the database and add subcategories and move the files into a subdir (subcategory) inside the previously mentioned dir (category). Another solution that is better if you are not willing to categorize the images is to divide them by date. You may include a date or date-time field in the database that describes the creation date of the image (or the upload date if you like) and divide the images into directories per month or per year or even both. Like making a directory 2008 and add inside sub-directories like 01,02,03... or Jan,Feb,Mar etc. Now when you query the database you may find from the creation date the directory that sores the image and everything is in order. For e.g. If the date you got from the database is 2008-01-23 and the image name is image01.jpg then the path would be: <?php $date = '2008-01-23'; $fname = 'image01.jpg'; list($year,$month,$day) = split('-',$date); $file_dir = '/data/images'; $path = $file_dir."/".$year."/".$month."/".$fname; print $path; ?> -- Thodoris

« previous php.general (#276569) next »