Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Image hosting and folder structure

    Hi,
    I'm currently coding my own little project, so users can create avatars / banners online with it. My current folder structure is: images/2012/06/14/. I have to store 3 images per user: background, text, final image.

    What is my aim, is that i could get as short as possible links to final images. I checked popular image hosting sites. Imgur direct links are like http://i.imgur.com/blabla.jpg and tinypic http://i50.tinypic.com/afisaf.jpg. I already have sub domain "i" and it points to my image dir.

    Does anybody know how those short links are made? I know, that i could just point i.domain.com to dir that contains final images, but i don't know that if it is best way, cause then one dir could contain thousands of images.

    And how much is recommended maximum amount of files per directory, so that it won't influence to performance?

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,512
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    It's all done with the .htaccess file in the form of a rewrite rule.

    .htaccess is a powerful thing to use, and there are many tutorials about it.

    Basically is rewrites the URL to whatever you want.

  • #3
    Regular Coder Redcoder's Avatar
    Join Date
    May 2012
    Location
    /dev/null
    Posts
    334
    Thanks
    2
    Thanked 48 Times in 47 Posts
    Quote Originally Posted by TheOner View Post
    What is my aim, is that i could get as short as possible links to final images. I checked popular image hosting sites. Imgur direct links are like http://i.imgur.com/blabla.jpg and tinypic http://i50.tinypic.com/afisaf.jpg. I already have sub domain "i" and it points to my image dir.

    Does anybody know how those short links are made? I know, that i could just point i.domain.com to dir that contains final images, but i don't know that if it is best way, cause then one dir could contain thousands of images.
    You could generate directory names using hashes. By that i mean like images/generatedhashname/image.jpg or whichever hash way you choose.
    A way to generate very short hashes is the crc32() hash.
    Examples when using Hashes,
    Code:
    14/06/2012/ThisisprincessDianaPicture
    With CR32 hash
    becomes

    Code:
    2615365075
    With MD5 hash:
    becomes:
    Code:
    9328e125b1bcc038741ecdfac8c90996
    With SHA1 hash:
    Becomes:
    Code:
    a41c024b2604a27bfcecef056d2756080dd8c6e1
    cr32 therefore makes shorter hashes suited for this type of thing.

    This way can be done when storing the directory names and retrieving the directory names from the database just like how you store and retrieve passwords.

    If this method helps you or is contentious in any way,let me know.

    For more info on how to implement the cr32 hash go to http://www.w3schools.com/php/func_string_crc32.asp or google it.

    Last edited by Redcoder; 06-14-2012 at 03:21 PM. Reason: Addition of further info.

  • Users who have thanked Redcoder for this post:

    TheOner (06-14-2012)

  • #4
    Senior Coder
    Join Date
    Sep 2010
    Posts
    2,211
    Thanks
    15
    Thanked 253 Times in 253 Posts
    I'm coding my own site to allow people to extensively edit images on line ( so far so good ) and I had the same problem. Since no files are kept on site, just temporarily uploaded, modified and downloaded, and the originals deleted, I did this. I made a folder in the site named Pool. All the user folders are made in Pool using the session_id, slightly changed, as the folder name. I felt this was much safer than having user images mixed together in one folder, or having them mixed with other files. Even if everything in Pool got deleted it would cause no serious problems. Makes it easier to clean up too.

  • #5
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Redcoder View Post
    You could generate directory names using hashes. By that i mean like images/generatedhashname/image.jpg or whichever hash way you choose.
    A way to generate very short hashes is the crc32() hash.
    Using crc32 was best idea so far! Only thing is that, can htaccess interact with MySQL somehow? One thing that i could think is that i make php file that takes GET value from URI and makes MySQL search with that. If there is row ID match, then it would echo real path. Only thing is that can htaccess & mod_rewrite send and get values from php. Have to take closer look to advanced htaccess tutorials.

    Big thanks to all for fast replys!


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •