Forum Moderators: coopster
$arrFiles = array(
// put legal files in here
"test.txt",
"example.txt",
);
if(isSet($_POST['file']) && file_exists($_POST['file']) && ( array_search($arrFiles, $_POST['file']) !== false )) {
$newFile = $_POST['file'] ."-". date("y-m-d His") .".txt";
// copy the file (Why do you want this anyway ?)
if (!copy($_POST['file'], $newFile))
exit("Could not copy the file");
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($newFile));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($newFile));
ob_clean();
flush();
readfile($file);
// delete file when it has been output to the client....
unlink($newFile);
exit;
}