EdgeWalker Posted June 6, 2007 Share Posted June 6, 2007 I have been having a problem where any normal method of forcing a download (using headers including things like "octet-stream" etc.) all work perfectly well for me ONLY if I save the .php file in ANSI encoding, and not UTF-8, which is what I would normally use for everything else. It took me a LONG time to figure out that was causing the problem, but why is this happening? Should I do everything in ANSI? Quote Link to comment https://forums.phpfreaks.com/topic/54509-char-set-bungles-forced-downloads/ Share on other sites More sharing options...
btherl Posted June 7, 2007 Share Posted June 7, 2007 Where do you have an option of ANSI or UTF8? What browser and OS are you using? "octet-stream" means that there is no character encoding, because no interpretation of the data should be done. So really you should never be asked what encoding to use if you are downloading an octet stream. Quote Link to comment https://forums.phpfreaks.com/topic/54509-char-set-bungles-forced-downloads/#findComment-269696 Share on other sites More sharing options...
EdgeWalker Posted June 7, 2007 Author Share Posted June 7, 2007 In this case, I'm referring to the character encoding of the text file that contains the script. I don't believe this should have *any* effect on the script, but after many trials, it does seem to. I'm using Win XP Pro/Apache 2/PHP 5 and my text editor (which provides a variety of text encoding options for plain text documents) is Notepad++ The browers I've tried are FF2.0.0.4, IE 7, IE 6. It's clearly something on the server side. On one hand, this isn't really a big deal since the script is working, but if I don't know why saving it in UTF-8 would cause it not to work, I can't be sure it won't happen in the future. Would it help if I was specific about my script? I will grab it from the server and post it... Quote Link to comment https://forums.phpfreaks.com/topic/54509-char-set-bungles-forced-downloads/#findComment-270066 Share on other sites More sharing options...
EdgeWalker Posted June 7, 2007 Author Share Posted June 7, 2007 These are the encoding options that are provided by my text editor, so you know what I'm talking about: Here is the script itself (it's a simple test of a forced download). What happens if I save as UTF-8 (which I normally do) the file (whatever I put there as a test) does force-download, but is usually short a few bytes and is (by virtue of that) corrupted. <?php $file = "testfile.jpg"; header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); //To force download, set content-type to octet-stream. header("Content-Type: application/octet-stream"); header( "Content-Disposition: attachment; filename=$file"); header( "Content-Description: File Transfer"); @readfile($file); ?> Quote Link to comment https://forums.phpfreaks.com/topic/54509-char-set-bungles-forced-downloads/#findComment-270071 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.