Here is the code that downloads the file to the user from the server from the "/ tmp" directory under the name "file.txt"

<?php if (isset($_GET['file'])) { $file = $_GET['file']; if (file_exists($file) && is_readable($file)) { header("Content-Disposition: attachment; filename=\"$file\""); readfile($file); } } else { header("HTTP/1.0 404 Not Found"); echo "<h1>Error 404: File Not Found: <br /><em>$file</em></h1>"; } ?> 

When downloading in different browsers, the name of the following character goes out, either "tmp_file.txt" or "tmp-file.txt"

Please tell me where is the reason?

What does this suffix "tmp _", "tmp-" add?

And why in different browsers different names on the output are obtained?

  • you give the file in an absolute way, with slashes that are directory delimiters, so the browser has no choice but to replace them with convenient browser characters - etki
  • @Etki and how to do otherwise? with location? Added "location = \" tmp \ "" does not work, it is probably not done that way)) - Vladimir Alexandrov
  • give to content-disposition filename without path - etki
  • This is understandable) and how to show him the path to the file? he himself does not find it by itself) - Vladimir Alexandrov
  • in filename only the file name is indicated, the path should not be specified anywhere since you give the file readfile($file) function - webDev_

0