Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-14-2012, 12:49 PM   PM User | #1
TheOner
New to the CF scene

 
Join Date: Jun 2012
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
TheOner is an unknown quantity at this point
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?
TheOner is offline   Reply With Quote
Old 06-14-2012, 02:52 PM   PM User | #2
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,055
Thanks: 8
Thanked 1,032 Times in 1,023 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
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.
mlseim is offline   Reply With Quote
Old 06-14-2012, 03:15 PM   PM User | #3
Redcoder
Regular Coder

 
Redcoder's Avatar
 
Join Date: May 2012
Location: /dev/couch
Posts: 309
Thanks: 2
Thanked 46 Times in 45 Posts
Redcoder has a little shameless behaviour in the past
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.
Redcoder is offline   Reply With Quote
Users who have thanked Redcoder for this post:
TheOner (06-14-2012)
Old 06-14-2012, 04:03 PM   PM User | #4
DrDOS
Senior Coder

 
Join Date: Sep 2010
Posts: 1,231
Thanks: 11
Thanked 156 Times in 156 Posts
DrDOS is infamous around these parts
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.
DrDOS is offline   Reply With Quote
Old 06-14-2012, 06:45 PM   PM User | #5
TheOner
New to the CF scene

 
Join Date: Jun 2012
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
TheOner is an unknown quantity at this point
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!
TheOner is offline   Reply With Quote
Reply

Bookmarks

Tags
folder, hosting, image, structure, subdomain

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:12 PM.


Advertisement
Log in to turn off these ads.