开发者

Implementing a PHP file uploader. Some basic technical questions

I am currently working on a file uploader (something like rapidshare) but on a very small scale.

  • However, one thing i am concerned about is how do i organize files ? If i place all files in a single uploaded directory, pretty soon (in about a month) the number of files in that directory will reach a million. Will this slow anything down on my system ? Will file accesses and lookups take more time ? How do i counter this problem ?

  • Also, i am looking to implement a multi-server upload. Meaning the admin can choose multiple servers where the file can be uploaded. How will this work ? Will the user upload to my server and my server will instantaneously upload via FTP or some other mechanism to the other server ?

  • The users should not be able to download the file via a download manager. Also, resume functionality should not be supported for normal users. How do i implement that. Can i provide a direct file location access to the user downloading the file ? Or will i have to "serve" the file using a s开发者_如何学运维cript and fopen, fread and print ?

Thanks for all your help i really appreciate any answers.


To be honest it looks like you're missing some major experience almost necessary to implement a system like to describe. Additionally "on a very small scale" definitely contradicts with a million files in less than a month.

I'll try to give answers to your questions.

  1. Organizing files is much about giving them reasonable names. If you let the user choose the filename, watch out that you filter that correctly to block attacks based on filenames like "../../../etc/passwd" (You SHOULD understand that.). I recommend you using hashes as filenames. Additionally you can assign them public "filenames" (actually aliases via a database). After uploading calculate a hash of the file. If the number of files increases you can store them in directories named after the first 2 chars of the hash. This is what Git VCS does and i really like that.

  2. What exactly do you mean by that? If you plan to have 1 single upload server and mirror the uploaded files to other servers you can easily separate these processes. Create an easy upload page and write another mirror script which sends the files e.g. via FTP to the other servers. Otherwise if you are about to create something called a cluster (several web servers for the same purpose performing load balancing and providing high availability), then there's no short answer on how to do this. Many wise men earn much money because they have the necessary experience and skills to implement such systems. If you are keen enough to do this on your own, you should go read some books about that.

  3. I don't want to question your motivation but why do you want to prevent the usage of download managers? These are very helpful to resume aborted downloads and thus help to lower the traffic of your server. It saves you traffic, bandwith, energy costs and CPU time. Is that too bad for you? More technically you need to configure your HTTP server, like e.g. Apache, to disable resume. I have no clue what the appropriate option is but I reckon there is one. Alternatively you can provide the files via a PHP script instead of linking to the file directly. The script gets the ID of the file via URL parameter and sends the content of the file (which must not reside in WWW root in this case) back to the client. This way it is your own responsibility to implement resumes or not and thus you can "disable" it easily. If you're actually about to avoid multiple downloads I would instead recommend using complex IDs like hashes (nobody can guess the link to download the file) and implementing some script which deletes the file after complete download. As I said disabling download managers harms you and your users.

I hope this is helpful to get a general image of the complexity of your idea.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜