Hello
I make a website for downloading different programs, download links are temporary (approx. Http://site.ru/downloads/bdb33c054e7f120b74f7867efcfa0633).
When you click on this link, the script sends the file through the headers and does not directly follow the link (this is if the file exists).
And how to make it so that in the absence of a file (the one that is given through headers) the link to the link is not carried out?
Thanks in advance!
The code on the page. $ file - the file address.
if (file_exists($file)) { // сбрасываем буфер вывода PHP, чтобы избежать переполнения памяти выделенной под скрипт // если этого не сделать файл будет читаться в память полностью! if (ob_get_level()) { ob_end_clean(); } // заставляем браузер показать окно сохранения файла header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . rand(0,999).'.'.end(explode(".", basename($file))) ); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); // читаем файл и отправляем его пользователю readfile($file); exit; }