Current location: Hot Scripts Forums » Programming Languages » PHP » uploading images in a single directory or not?


uploading images in a single directory or not?

Reply
  #1 (permalink)  
Old 03-16-08, 06:31 AM
macintosh macintosh is offline
Newbie Coder
 
Join Date: Mar 2007
Posts: 84
Thanks: 1
Thanked 0 Times in 0 Posts
uploading images in a single directory or not?

hello experts
im making an upload script where users upload images. Images are stored in a single directory.
I want to know, if there are large number of images in one directory, does it cause images to load slow? is it better idea to store large number of images (eg. 20,000) in One directory, or i should create different directories?
How can i make any condition to create new directory automatically? eg. if there are 1000 images in one directory then it should create new one.
okay, if this can be done, then there is a problem in accessing images. for example, when displaying image, how can i know the new image path? (eg. how can i know that in which directory the image is located.

please let me know about any ideas.
thanks
Reply With Quote
  #2 (permalink)  
Old 03-16-08, 06:37 AM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
I doubt it would make any difference really. The system will have to look up the actual starting sector on the disk for the file, then the head moves and reads that sector up to the end of the file. It doesnt matter if there is a million different folders, its not going to make much/any difference

Jay
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
Reply With Quote
  #3 (permalink)  
Old 03-16-08, 06:47 AM
macintosh macintosh is offline
Newbie Coder
 
Join Date: Mar 2007
Posts: 84
Thanks: 1
Thanked 0 Times in 0 Posts
Thanks Jay, as im not an expert in php, so i try to check things around, for example, i noticed that no any image uploading website uploads the images to a single directory. they always make different directories, for example
Quote:
img/img02/4/1/10/f_realfriendsm_9e6d6ea.jpg
i wonder what is the purpose of doing this?
Reply With Quote
  #4 (permalink)  
Old 03-16-08, 06:50 AM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
Could be to categorise, or to help make more smaller named files. those urls may be re-written also for searching purposes, and may not actually be stored like that structure whatsoever on the actual server
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
Reply With Quote
  #5 (permalink)  
Old 03-16-08, 06:53 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
I really would suggest using different directories. Not even because the computer can't handle it or anything, but you won't be able to work with the folder properly once you have thousands of files in there. Your FTP client will go crazy (most likely), and it'll also take longer to find the files you're looking for etc.

And the big image hosting sites use even different servers, not only different folders...
Reply With Quote
  #6 (permalink)  
Old 03-16-08, 06:56 AM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
yeah, forgot to say about that. tinypic for example uses subdomain names that start iXX wher XX is a 2 digit number. I am assuming these are to point to different servers since the number of images they hold are enormous. I think photoboucket averages at about 90 images a second uploaded. Try loading one directory of them in your FTP Client
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
Reply With Quote
  #7 (permalink)  
Old 03-16-08, 07:11 AM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by macintosh View Post
How can i make any condition to create new directory automatically? eg. if there are 1000 images in one directory then it should create new one.
look here for how to count the number of files in a directory. Are you storing any info on the files in a db that could be used to count the number of files per dir also, and keep track of the current dir name
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
Reply With Quote
  #8 (permalink)  
Old 03-16-08, 07:14 AM
macintosh macintosh is offline
Newbie Coder
 
Join Date: Mar 2007
Posts: 84
Thanks: 1
Thanked 0 Times in 0 Posts
Thanks Nico and Jay... I agree, that.
Now the problem im facing is, as i was using a single directory. for example "images".
Now when i want to link the image, i know exactly the image path. eg. <img src ="images/1.jpg">
Now, if i create the dynamic directory, how can i figure out that the image is located in which directory.
please suggest me what is the best way to create automatic directories and then how to get the path of the images to that directories.
thanks alot once again.
Reply With Quote
  #9 (permalink)  
Old 03-16-08, 07:21 AM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
Well if the first 1000 are located in directory 1(0.jpg to 999.jpg),(1000.jpg to 1999.jpg) in dir 2 then you would use the following formula

directory number = rounded (image number / number of images per dir) + 1

so in this instance, you would have something like the following
PHP Code:

#imgnum is the current image numbers value that you want to find
$dir intval($imgnum/1000) +1;
#$dir should now hold the right value 
Jay
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
Reply With Quote
  #10 (permalink)  
Old 03-16-08, 07:21 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
I'd create them based on a date. For example create each month a new folder:
PHP Code:

$folder sprintf('images/%d/'date('Ym'));


if (!
is_dir($folder))
{
    
mkdir($folder0755);

You can store the paths in a database, for example.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to locate a tool to compress images on client side before uploading indianajns Script Requests 7 10-10-06 09:21 PM
CHMOD images directory to 777 killerbanana PHP 1 01-02-05 09:54 AM
Uploading Images Using Forms rockitdev PHP 1 12-08-04 06:50 PM
Need Epinions-lite system in PHP & MYSQL wali001 Job Offers & Assistance 4 01-12-04 06:02 AM
Showing images in a directory Bob PHP 4 08-25-03 08:16 AM


All times are GMT -5. The time now is 07:38 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.