goldfish is a quite simple autoresponder for Postfix in conjunction with MySQL, written in PHP. It consists of only one PHP file which can be started through a cronjob.
Download Goldfish Autoresponder PHP Script
It must be noted that in the above example ,emphasis is made on pdf files.But you can always add more headers to suit your needs.<?php
// place this code inside a php file and call it "download.php"
$path = $_SERVER[DOCUMENT_ROOT]."/path2file/"; // change the path to 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 different extensions like doc excel and more
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>
?>
Note that these two PHP Scripts are WORKING!, so you can begin using it straightaway.If you have any suggestions regarding the script please feel free to share it with us.Feel free to edit the above two scripts to suit your personal needs.<?php
session_start();
/*
Note that this PHP Script does not show Confirmation message when the Download Completes.You can make the
required changes to suit your needs
*/
//You Can Change the URLs to suit your needs
$error=http://errorexample.com;
$filepath=/my/local/file/path/to/images/;
$getfile = basename ($getfile);
if (isset($_POST[downl_file]) && basename($_POST[downl_file]) == $_POST[downl_file]) {
$getfile = $_POST[downl_file];
$_SESSION[downloadfile] = $_POST[downl_file];
} else {
header("Location: $error");
exit;
}
if ($getfile) {
$path = $filepath . $getfile;
// check that it exists and is readable
if (file_exists($path) && is_readable($path)) {
// fetch the file size and send the respective headers
$size = filesize($path);
header(Content-Type: application/octet-stream);
header(Content-Length: . $size);
header(Content-Disposition: attachment; filename= . $getfile);
header(Content-Transfer-Encoding: binary);
// opens in read only mode
// Ignore error message
$file = @ fopen($path, r);
if ($file) {
// stream the file and exit the script once download is completed
fpassthru($file);
exit;
} else {
header("Location: $error");
}
} else {
header("Location: $error");
}
}
?>