1
  1. main link is: yourname.com/movie/film.mkv

  2. download link for users: yourname.com/2012/Esx123Sxzz96/film/

How to switch link 2 to link 1 without users seeing the main link and it appearing in a download manager?

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
Mohammad
  • 197
  • 3
  • 12

2 Answers2

1

First, use a .htaccess to prevent direct access to the /movie/ folder if you want to protect your site from having users accessing directly the data.

Then, it's a matter of passing the file through php, sending the appropriate header first, see this thread for more information.

If your movies are large files, consider alternate methods to send the file, such as x-sendfile which I never used on my own, see this answer for more information.

Edit: if you don't have user authentication to do, stats tracking, download limiting, etc... and simply want to rewrite the path you could use an .htaccess to rewrite the path (though with the kind of 2nd path you provide, it seems like you need logic to extract the desired path). If you don't care that the user knows the "secret path" after clicking the link, you could simply use a header('Location: yourname.com/movie/film.mkv"); - this would allow the user to set a bookmark to your file and never have to go through your yourname.com/2012/Esx123Sxzz96/film/ path again.

Re-Edit Apparently, the real question is how to create a whole system where media can be stored and then accessed through a "different" path, hiding the source.

What I would do is build a list, or database, for every media you want to store. When adding an item to the list, give it a unique ID. To keep things simple, lets start with 0 and increment by one for each file. You could store more information from your media in the list/database, such as the length of each movie, the filesize, etc...

Then, when you want to list these files to the user, you simply hash the id, you can use something like this, which will create a string such as U6dc... can now build links using: <a href="mysite/files/$hashedValue">Link for $filename</a>.

Intercept the calls to mysite/files/ using a .htaccess and redirect it to say files.php which will be responsible to translate the parameter U6dc into an ID in your list. Once you have this ID, it's easy to find the media on your drive and send it to the user, maybe using x-sendfile, up to you.

Community
  • 1
  • 1
emartel
  • 7,712
  • 1
  • 30
  • 58
  • It doesn't seem logical to pass a _movie_ through PHP. – Lightness Races in Orbit Nov 27 '12 at 15:51
  • Care to propose a better solution? – emartel Nov 27 '12 at 15:52
  • Terrible advice. And sorry, it is logical once you read the requirement, protecting the file from users who aren't allowed to get the movie or whatever the file is. – N.B. Nov 27 '12 at 15:52
  • @N.B.: Why is it terrible advice? Rewriting URLs is a pretty common practice. Is everyone wrong? And I did read the requirement -- why does that make it logical to pass what might amount to several megabytes through a PHP script? That's never going to be logical - it's going to be insane. – Lightness Races in Orbit Nov 27 '12 at 15:54
  • 2
    Because you cannot implement authentication mechanisms if you use simple URL rewriting. Also, you don't have to pass the entire file at once, you can send it in chunks which is the actual method used instead of PHP's `readfile`. Therefore, if you want to implement auth / counters / stats / whatever - it is logical. – N.B. Nov 27 '12 at 15:55
  • this link can other format , link 2 have mirror link 1 without user understand it – Mohammad Nov 27 '12 at 15:57
  • @N.B. Every single answer on the linked question uses `readfile`. Then this answer should provide the chunked implementation instead to present a "sane" solution. – Lightness Races in Orbit Nov 27 '12 at 15:59
  • @LightnessRacesinOrbit - The answer presented the means, not the performance optimization. :) – N.B. Nov 27 '12 at 16:01
  • @N.B. Honestly I think this goes beyond mere optimization. If the OP wanted to sort 30,000 filenames, you wouldn't suggest bogosort then write an addendum in the comments that the solution should be optimized later! :P – Lightness Races in Orbit Nov 27 '12 at 16:04
  • @LightnessRacesinOrbit - actually, I would show the person the way, and if they stumble upon the performance wall - I'd explain how to get around it (given the fact they ask the question). Handing out a copy/paste example isn't really going to help someone to learn, will it? :) – N.B. Nov 27 '12 at 16:07
  • @N.B.: I never suggested that. But suggesting bogosort to order 30,000 filenames is _more harmful than helpful_, and I feel that this answer as it stands right now does fall into that category. That is all! – Lightness Races in Orbit Nov 27 '12 at 16:12
  • @Mohammad if you read my answer you would have something to get you started. If performance is an issue I would check `x-sendfile`. If you don't need ANY validation or stat tracking and simply want to rewrite the path, then use a `rewrite` rule in your `.htaccess` – emartel Nov 27 '12 at 16:25
  • @Mohammad first, define what download manager is for you, then what do you mean by how set link? According to your example you want something like `The Link`? – emartel Nov 27 '12 at 16:35
  • Wait... what? Your question is not how to hide a file but how to write a link? Or you want us to provide you with how to write a content management system that assign files to some ids which can then be accessed through links based on these ids? – emartel Nov 27 '12 at 16:59
  • @emartel yes i want provide – Mohammad Nov 27 '12 at 17:04
  • @Mohammad your sentence is pretty rude but I'll assume it's because English is not your primary language... – emartel Nov 27 '12 at 17:05
0

With .htaccess you can declare your own conditions.