Fix file endcoding when downloading a file from Linux to Windows in php -


OK I have a problem. I have a Linux web server (RHEL 4 with APS2) for an application A part of this application is a set of PHP scripts used. I created a script that accepts some form variables and then downloads a file to the user. Code at:

  Header ('Content-Description: File Transfer'); Header ('content-type: application / octet-stream'); Header ('content-dispute: attachment; filename ='. $ DestFileName); Header ('expiration: 0'); Header ('Cash-Control: Required-Modified, Post Check = 0, Pre-Check = 0'); Header ('pragma: public'); Header ('content-length:'. File size ($ full text)); Ob_clean (); Flush (); Readfile ($ fullpath);  

All this works fine, and the file is downloaded. But there is a problem. These files are being downloaded from the Linux box, a Windows machine (always). The problem is encoding when you see the file on the linux box, all the text is aligned and all columns look fine. (Files are just flat text files). But when the file is downloaded to the Windows box, and is opened in Notepad, the file is all bloated, and nothing has been aligned. You also see weird charactors (which look like a box but this is the usual representation for the unknown charactor only). When this file is imported into another program, it does not work.

However, when I open the file in WordPad, all the text looks correct. If I save it from WordPad, it will import correctly, and it will look right in the Notepad.

I do not have much information on file encoding, so it would be great to download the file how I can encode before sending the user.

I tried to replace readfile ($ fullPath); With:

  $ handle = @ fopen ($ full path, "R"); {$ Handle handle} $ buffer = str_replace ('\ n', '\ r \ n', $ buffer); $ buffer echo ($ (handle $ FIFF) ;} Fclose ($ handle);}  

Thanks!

There is a problem with the following line:

  $ buffer = str_replace ('\ n', '\ r \ n', $ buffer);  

You must use double quotes here. "\ N" Newline is '\ N' literal character sequence backslash-N:

  # php -r "var_dump ('\ n', \ "\ N \"); "string (2)" \ n "string (1)" " 

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -