2

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);
?>
Chong Lip Phang
  • 8,755
  • 5
  • 65
  • 100

1 Answers1

2

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");
liyakat
  • 11,825
  • 2
  • 40
  • 46
  • I could not get it to work with the first method but the second method using "Location" seems to work well. Thank you. – Chong Lip Phang Jul 26 '13 at 06:00
  • Now a second problem arises. Using this new technique, it seems that the users can still see the download link in a download manager such as DAP. So is there really a way to hide the URL altogether? – Chong Lip Phang Jul 26 '13 at 06:22
  • it is software, i dont think so we can do it – liyakat Jul 26 '13 at 06:24