Jump to content

headers questions


holowugz

Recommended Posts

How do you force the download dialog box come up for a file using headers.

for example when someone goes to my page:@

www.somewhere.com/download_file.php?File=cheese

i want them to download cheese.zip or what ever, i am told you can do that with headers but how?
Link to comment
Share on other sites

[code]$ name = $_GET['File'];
$ size = f ilesize($name);
$ type = m ime_content_type($name);
$ content = f ile_get_contents($name);

h eader("C ontent-length: $ size");
h eader("C ontent-type: $ type");
h eader("C ontent-Disposition: attachment; f ilename=$name");
echo $ content;[/code]

Remove the spaces in the function names and such.
Link to comment
Share on other sites

Not necessarily...you can put it where ever you want, you just need to either pass the location as a part of the variable, or if they are all in a different sub directory, you can code it that way. Or you can store file names and locations in an array, then pass the array key as the var...kind of like an id.

It doesn't have to be in the same directory.
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.