1

I have some problems with sending files with PHP. I would like to send a file named .version (Note the dot and nothing infort of it). The file is sent correctly but my browser renames it to version. Therefore the file looses its functionality. The file has to be named like this.

This is the code I use:

<?php
  header("Content-Description: File Transfer");
  header("Content-Type: text/version");
  header("Content-Disposition: attachment; filename=\".version\"");
  header("Content-Length: " . filesize($file));

  readfile($file);
  exit();
?>

$file is the correct internal path to the file.
Other headers like the expires header are set in my server config.

If there is information missing I will add if if you ask for it!

BrainStone
  • 3,028
  • 6
  • 32
  • 59
  • 1
    is it going to a windows machine? they dont allow files starting with a dot –  Jun 12 '14 at 21:42
  • How about `header("Content-Disposition: attachment; filename='.version'");` ... – Hackerman Jun 12 '14 at 21:42
  • @Dagon Why not preparing an answer? (It might be a duplicate, however) – hek2mgl Jun 12 '14 at 21:47
  • " Why not preparing an answer" not sure what you mean –  Jun 12 '14 at 21:53
  • @Dagon I can easily create the file by hand on an windows machine. If a simple program can do it why can't my browser? Robert Rozas I will try that! – BrainStone Jun 12 '14 at 21:58
  • @RobertRozas no. That doesn't work. The file will be saved as `.version'`. – BrainStone Jun 12 '14 at 22:01
  • The browser realizes that there shouldn't be a dot in front of it and fixes it, so what's the problem? Users have an option to rename a file before saving anyway. – developerwjk Jun 12 '14 at 22:40
  • Try escaping the dot `filename=\"\.version\"");` – Funk Forty Niner Jun 12 '14 at 23:30
  • Didn't work... Sometimes windows is simply annoying me! – BrainStone Jun 12 '14 at 23:34
  • Try `filename=\".version\"");` or `filename='.version'");` - `.` is the ASCII/HTML equivalent for a dot, as per http://www.ascii-code.com/ – Funk Forty Niner Jun 12 '14 at 23:46
  • @Fred-ii- No doesn't work either! – BrainStone Jun 12 '14 at 23:52
  • 1
    After a fair amount of research and testing, I'm afraid to say that you're not going to be able to use that type of file (naming) convention. Even when trying to do a simple `href=".version"` wouldn't let me download it under that name. Consult this answer on SO http://stackoverflow.com/a/68742/ (for some added info), where it was pulled from http://php.net/variables.external – Funk Forty Niner Jun 13 '14 at 01:06

0 Answers0