Here are the code snippets...
in downloads.htm, the javascript:
t = './downloads.php?&file=' + file + '&name=' + cname + '&email=' + cemail;
t = encodeURI (t); // encode URL
// assign form's action a new value. Original "action" value will be overwritten.
f1.action = t;
f1.submit(); // submit form using javascript
.......
the function calls in downloads.php:
<?PHP
require_once('functions.php'); // Include functions
$status = 0;
$file = $_GET['file'];
$name = $_GET['name'];
$email = $_GET['email'];
//download first
$status = downloadFile($file,$status);
if ($status == 0) {
$sub = "Confirmation: BitTec Systems Product Download";
$br = "\n";
$messagebody = "Hi " . $name . $br . $br;
$messagebody .= "Congratulations for downloading our product." . $br;
$messagebody .= "Please unzip the downloaded file and read through the
......
//we set the headers to null as we don't want to add any
$messageheaders=null;
$status = emailer($name,$email,$sub,$messagebody,$messageheaders,$status); // Define the function.
}//if
exit(0);
?>
the code in functions.php:
<?PHP
function downloadFile($file,$status=1) // Define the function.
{
$dir = 'downloads/';
if ((isset($file))&&(file_exists($dir.$file))) {
$fn='"' . $dir.$file . '"';
$fs=filesize($dir.$file);
$status=0;
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Description: File Transfer");
header("Accept-Ranges: bytes");
header("Content-type: application/octet-stream");
header('Content-Disposition: attachment; filename="' . $file . '"');
header("Content-Transfer-Encoding: binary");
header("Content-length: ".filesize($dir.$file));
readfile("$dir$file");
}//if
return $status; // Return the status
}//downloadFile
function emailer($name,$to,$sub,$msg,$hdr,$status=0) // Define the function.
{
$br = "\n";
$eLog="../tmp/mailError.log"; //"../../tmp/mailError.log";
//Get the size of the error log
//ensure it exists, create it if it doesn't
$fh= fopen($eLog, "a+");
fclose($fh);
$originalsize = filesize($eLog);
ini_set('sendmail_from', 'info@bittecsystems.com');
//send to email
mail($to,$sub,$msg,$hdr);
clearstatcache();
$finalsize = filesize($eLog);
//Check if the error log was just updated
if ($originalsize != $finalsize) {
$status = 2;
}//if
if ($status != 2) {
$originalsize = filesize($eLog);
//send to self
$messagebody = "Downloaded By: {$name}" . $br;
$messagebody .= "Downloader E-mail: {$to}" . $br;
mail('info@bittecsystems.com','Product download confirmation sent',$messagebody,$hdr);
clearstatcache();
$finalsize = filesize($eLog);
//Check if the error log was just updated
if ($originalsize != $finalsize) {
$status = 2;
}//if
}//if
return $status; // Return the status
}//emailer
?>
hope this makes sense now
thnx
BitTecSystems