tags:

views:

138

answers:

2

I've never really understood on how to do it. I want to where where I can type my address, followed by /index.php?=<a file that is on the FTP>.exe. From there, I would be direct to a page that has a download now button and maybe something like a ad.

Anyone have any tutorials or guides that I may look at?

+3  A: 

Im gonna bite ...

The PHP script ensures the file is not accessible from the outside, and only on a per-request basis with possible authentication. When you see:

download.php?file=sdjasdk.exe

The download script looks a bit like:

<?php
    if( $_SESSION['auth'] == TRUE){
        $file = fileopen($whatever);
        echo "mimetype crap"
        //spit out file
    }else{
        echo "not authorized bozo"
    }
?>

DOne.

Aiden Bell
you would probably send the "mimetype crap" in the response header with header() rather than echo
Tom Haigh
Just an example ... read as "code your own"
Aiden Bell
+2  A: 

I think he is on about simple $_GET requests >.<

<?php

$file = $_GET['file'];

if (file_exists($file)) {
   header('Content-Type: application/octet-stream');
   echo file_get_contents($file);
}

?>

Ofcourse this is a very basic example with no security at all. Its not reccomended for you to use this in production without upping security on it.

Ozzy
Use readfile() instead of file_get_contents() - it's much more efficient in this sort of situation.
ceejayoz
To further explain what ozzy means when he points out that their are security issues with this script, consider what would happen when $_GET['file'] = '/etc/passwd' or '../../../../../../etc/passwd', etc. For these reasons, you probably want to do something like $file = '/my/downloads/dir/' . basename($_GET['file']);
Frank Farmer