Re: Character encoding hell
| From: | Mari Masuda | Date: | Tue, 26 Oct 2010 17:32:00 +0000 |
| Subject: | Re: Character encoding hell | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-309095@lists.php.net to get a copy of this message | ||
On Oct 26, 2010, at 10:10 AM, Marc Guay wrote:
>> A windows server, or windows client to the same Linux server? I believe that this issue is
>> starting to get a bit over my head, with the different operating systems involved and such.
>
> Windows server. This is over my head, too. I'm guessing that Windows
> and Linux encode filenames differently and when I transferred the file
> from one to the other, some kind of adjustment was made.
>
> Marc
I think one way to do this is something like this (untested):
1. Put all of your files in some directory on the server.
2. Change your <a href="http://example.com/encoded-file-name.pdf">my
file</a> to <a href="http://example.com/download-file.php?fileID=xxx">my
file</a> where xxx is the urlencoded version of "encoded-file-name.pdf". (xxx could
also be a fileID number if stored in a database.)
3. In download-file.php do something like this:
<?php
$parent_directory = "/path/to/parent/directory/"; // can be in or out of web root
if (file_exists($parent_directory . "encoded-file-name.pdf")) {
$data = file_get_contents($parent_directory . "encoded-file-name.pdf");
$file_name_with_french_chars = rawurldecode("encoded-file-name.pdf");
header("Content-type: application/octet-stream");
header("Content-disposition: Attachment;
filename=\"$file_name_with_french_chars\""); // this line assigns the
"nice" looking name as the file name
echo $data;
}
?>