Jump to content


Photo

headers questions


  • Please log in to reply
3 replies to this topic

#1 holowugz

holowugz
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts

Posted 18 March 2006 - 02:19 PM

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?

#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 18 March 2006 - 03:31 PM

$ 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;

Remove the spaces in the function names and such.

#3 holowugz

holowugz
  • Members
  • PipPipPip
  • Advanced Member
  • 46 posts

Posted 18 March 2006 - 09:56 PM

doe that mean the file has to be in the same directory as ths script?

#4 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 18 March 2006 - 10:07 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users