Re: Character encoding hell
| From: | Bastien Koert | Date: | Tue, 26 Oct 2010 18:01:17 +0000 |
| Subject: | Re: Character encoding hell | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-309099@lists.php.net to get a copy of this message | ||
On Tue, Oct 26, 2010 at 1:32 PM, Mari Masuda <mbmasuda@stanford.edu> wrote:
>
> 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;
> }
> ?>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
This approach is what I wanted to suggest as well. You can simulated a
db with an XML file if you wanted to and even assign the IDs as
numerical to make life really easy
--
Bastien
Cat, the other other white meat