First of all I ask for an apologize, I know this question had been asked and already been answered but I still can not figure out what to do.
I put my files outside and before of root directory and want to access it when a customer purchases a file. I know I can use this method for downloading but I want this to get the file and let me to send it into other page and there customer click on the link to download it and also mention that a customer may have purchased many files.
How can do the same for all files? Should I put them in a loop?
Here is my code:
<?php
$file = 'monkey.gif';
if (file_exists($file))
{
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment;
filename='.basename($file));
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($file));
ob_clean();
flush();
readfile($file);
exit;
}
?>
Thanks in advance.