0

I have some files in a server, there are many articles pointing to the files, sometimes the url are misspelled. I want to serve the file no matter what the url was. For that I want the file on the server to be renamed before getting downloaded by a user without actually renaming the original file. Since there would be many requests to the original file. For example. If the file is Book of Reliable.pdf , and the url the user clicks is http://example.com/Book of Reliance.pdf , I want the user to download the file as Book of Reliable.pdf

I think we can achieve this by renaming the actual file. But I want the original file to be untouched.

  • Does this answer your question? [php - How to force download of a file?](https://stackoverflow.com/questions/531292/php-how-to-force-download-of-a-file) – OMi Shah Oct 30 '22 at 04:18

1 Answers1

1

Simulate a rename using HTTP headers, like:

$name = 'my-file-name.txt';
header('Content-Disposition', 'inline; filename="' . $name . '"');

Note to replace inline with attachment if you want the Browser to show "Save As..." dialog.

Top-Master
  • 7,611
  • 5
  • 39
  • 71