Reputation: 9279
I have a PHP script that is supposed to allow the users to download a file without showing the URL. When I try out the following, the file I download is empty. Could someone please help?
<?php
$file_name = 'test.exe';
$file_url = 'https://www.example.com/' . $file_name;
header('Content-Type: application/octet-stream');
header("Content-disposition: attachment; filename=".$file_name);
readfile($file_url);
?>
Upvotes: 2
Views: 5449
Reputation: 11853
you should use like this
header("Content-Type: application/octet-stream");
header("Content-Transfer-Encoding: Binary")
header("Content-disposition: attachment; filename=\"file.exe\"");
echo readfile($url);
also content type based on your file application/zip, application/pdf etc
AND or better one for exe
header("Location: $url");
Upvotes: 2