I am trying to make a custom download page. Seems pretty simple. A link on my HTML page (index.html) that goes to a php page that is supposed to auto download the file. But it's not working.
Here are the scripts:
downloads.php
PHP Code:<?php
/*
This download script can send an email and/or log the download
There are two variables below - one for the email address and one for a download log file
Set both vraiables to the values you want
If you do not want either an email or log entry, comment out the respective line
So for example of you do not want an email sent, put a // in front of the $emailAddress line - same for the $downloadLogFile line
*/
//$emailAddress = "mail@yourdomain.com";
$downloadLogFile = "downloads.dat";
$directory = "/FrozenCoyoteLabs/Flash/Programs"; // the relative directory that has the downloads - can be ./ for the current directory
putenv('TZ=EST5EDT'); // eastern time
// nothing should be changed below this line
$filename = $_GET['file'];
$path = "$directory$filename";
if(file_exists($path) AND substr_count($filename,"/") == "0") {
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=$filename");
header("Content-Length: ".filesize($path));
readfile("$path");
if (isset($emailAddress)) {
$message = "File name: " . $filename . "\n\n";
$message .= "Time of the download: " . date(" F d h:ia") . "\n\n";
$message .= "Browser: " . $_SERVER['HTTP_USER_AGENT'] . "\n\n";
$message .= "Page Requested: " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . "\n\n";
$message .= "Referer: " . $_SERVER['HTTP_REFERER'] . "\n\n";
$message .= "IP Address: ". $_SERVER['REMOTE_ADDR'] . "\n\n";
$message .= "Hostname: " . gethostbyaddr($_SERVER['REMOTE_ADDR']) . "\n\n";
mail($emailAddress,"Download notification",$message, "From: Website <>");
}
if (isset($downloadLogFile)) {
$downloadLogRecord = $filename . "||" . $_SERVER['REMOTE_ADDR'] . "||" . gethostbyaddr($_SERVER['REMOTE_ADDR']) . "||" . date('Y-m-d H:i:s') . "\r\n";
$file_pointer = fopen($downloadLogFile,"a");
fwrite($file_pointer,$downloadLogRecord);
fclose($file_pointer);
}
}
?>
Now when I go to this page through the html link i get "download.php?file=filename.zip" in the URL. but it's a blank page with "done" in the status bar and filename.zip does not download. ideas?



Reply With Quote


(:

Bookmarks