Working with CakePHP and Java Web Start I generate the necessary .jnlp file in the controller, in which, among other things, I set the file name as a header field. This works fine until I try to use special characters in file names. However, I would like to include every character that is possible on major operating systems as a file name. Therefore, I am trying to remove all invalid characters by replacing them with blank lines. But there seems to be a problem with spaces that should be resolved in file names.
What code:
$panel_id = 1 $panelname = 'whitespace s'; $filename = sprintf('"Project_%d_%s.jnlp"', $panel_id, $panelname); $invalid_chars = array('<', '>', '?', '"', ':', '|', '\\', '/', '*', '&'); $filename = str_replace($invalid_filenamechars, '', $filename); $this->header('Content-Disposition: attachment; filename=' . $filename);
When I do this, the final file name in the header will be "Project_1_w h i tespace", and Windows 7 wants to save the file as "Project_1_w". Does my OS seem to not accept irrevocable spaces in file names? I would be pleased with this explanation, if not for the following: I left lines 4 and 5, so that the code looks
$panel_id = 1 $panelname = 'whitespace s'; $filename = sprintf('"Project_%d_%s.jnlp"', $panel_id, $panelname); $this->header('Content-Disposition: attachment; filename=' . $filename);
And now Windows is ready to save the file with all its spaces, but I canβt understand why. If I look at the file names in the headers using wirehark, they are both the same. And if the sprintf string is replaced with $filename = 'whitespac e' or even $filename = $panelname , it shortens the file name, as in the first code. But I can replace sprintf with the dottet-string-concat syntax, and it works.
Can someone tell me what I'm missing?