Jump to content

Char set bungles forced downloads?


EdgeWalker

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

These are the encoding options that are provided by my text editor, so you know what I'm talking about:

encodingxm3.jpg

 

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);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.