Jump to content

For PHP Geniuses!!! I Have a Question


Menan

Recommended Posts

hi every one , this my first post.i am kind of new to php but i learned all of ur w3schoools tutorials. great and simple thanks. By the way my question is i saw some websites they let the people download files. but if u look at the direct download link it is like hidden.if u see gmail.com if u view ur .rar extension attachment u won't see it like .rar it will be some thing different. i think they used database but even if u use database u will be abe to see it.can some one tell me how they doing it.ThanksMenan

Link to comment
Share on other sites

It's quite simple, this is just the basics, not much code. (The best way to learn is to figure out it at your own)Create a table (in a database, pref. use MySQL; I call it downloads here...) where you save info. about all files that the users should be able to download.(Columns coculd be: id, file, title, description, downloadcount etc.)Then You should create a admin. script that you can use to simply add the files.Create a script that shows all files/downloads.Here comes the big "secret":The downloadlink for each file should look someting like this

?do=download&file=$id or download.php?file=$id

where $id is the id of the file from the DB.Then the script that is called (either by include, in the first example, or a own file, last ex.)Should look something like this (This is "half pseudo"):

<?  $id = $_GET['file'];   // Open database...  ...  // Get file  $query = "SELECT file FROM downloads WHERE id=$id";  $db->RunQuery( $query );  // Depending on which db-motor you use, this will be different  $file = $db->GetResult();  // Here is the important thing;  header("Location: http://yoursite.com/files/$file");  // This line must be before any output (of HTML) // Close DB...?>

Hope you got it... :?)Good Luck, and don't panic

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...