Endless Paradigm

Full Version: looking for a PHP download script
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
That will give the user a file when clicked, i.e.

Code:
<a href="download.php?file=pooper.zip">DOWNLOAD</a>


I've got one of those now, and it works great,

PHP Code:
<?php
 
// place this code inside a php file and call it f.e. "download.php"
$path = $_SERVER['DOCUMENT_ROOT']."/path2file/"; // change the path to fit your websites document structure
$fullPath = $path.$_GET['download_file'];
 
if ($fd = fopen ($fullPath, "r")) {
    $fsize = filesize($fullPath);
    $path_parts = pathinfo($fullPath);
    $ext = strtolower($path_parts["extension"]);
    switch ($ext) {
        case "pdf":
        header("Content-type: application/pdf"); // add here more headers for diff. extensions
        header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachment' to force a download
        break;
        default;
        header("Content-type: application/octet-stream");
        header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
    }
    header("Content-length: $fsize");
    header("Cache-control: private"); //use this to open files directly
    while(!feof($fd)) {
        $buffer = fread($fd, 2048);
        echo $buffer;
    }
}
fclose ($fd);
exit;
// example: place this kind of link into the document where the file download is offered:
// <a href="download.php?download_file=some_file.pdf">Download here</a>


except what I really want is one that when you right click, and save as, all you get is the PHP, or somethingorother, so it basically forces users to left click on it.

Halp?

:D

id help but i don't know a spec of php :\
lol I love useless posts!
nurehtix Wrote: [ -> ]lol I love useless posts!

like this? <3
Your post is far less useless. :3
Right-click » Save As essentially does the same thing as left-clicking and then saving the page.

There may be some "dirty tactics" you can do but you can never guarantee that they'll work always.
Well I don't really care  if it always works, I'd just like to thwart the average user.

Really, the only reason I'm bothering is to track downloads; to see how many people are downloading our releases, and the tracking script is an 'onclick' one.
i had a useless post because the thread was dying >:) there is a method in my madness
The thread was dying, even though it's still the first thread on 'Latest Threads'?
yes i WAS the first to reply :)
Pages: 1 2 3
Reference URL's