Re: Character encoding hell

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux