treng
treng

Reputation: 1685

Store uploaded user images

This is theoretical question.

Twitter keeps user profile images as following :

https://twimg0-a.akamaihd.net/profile_images/2044921128/finals_normal.png

It's impossible to imagine that they have a server which contains 2044921128 directories (for example).Maybe this URL is created using mod_rewrite?

So how to store an extremely large number of user images? How to complete this scheme:

  1. User chooses and PHP script uploads an image that's supposed to be his profile picture.
  2. PHP script renames it, sets the PATH to store this image, moves it and finally adds this path to database for further use.

So how PATH must look like?

Upvotes: 1

Views: 169

Answers (2)

raidenace
raidenace

Reputation: 12826

Most OS-es discourage having more than 1024 directories/files within a single directory as any number above that slowly makes scanning and locating specific resources within it slower, so I think it is safe to think that akamai would not be having 2044921128 directories within profile_images!

Either it is a special unique identifier number generated within profile_images or one of the numerous ways in with url routing can be used to locate a resource. In any case, I do not think it would correspond to the number of directories..

Upvotes: 1

Eric J.
Eric J.

Reputation: 150108

Nothing says that Akamai (which stores the pictures for Twitter based on your URL) actually stores the files in a directory structure. It's entirely possible that they are stored in memory (backed by say a directory structure), in a database (SQL / NoSQL) or any other storage mechanism that Akamai finds efficient.

You can route all requests for a URL that start with

https://yourService.com/profile_images/

to a PHP script of your choice that then parses the rest of the URL to determine which image is being requested and store/retrieve from whatever storage mechanism you want (perhaps a database) based on the parsed URL.

Here's a short blog post that shows one method of doing that using mod_rewrite

http://www.phpaddiction.com/tags/axial/url-routing-with-php-part-one/

Upvotes: 1

Related Questions