holowugz Posted March 18, 2006 Share Posted March 18, 2006 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=cheesei want them to download cheese.zip or what ever, i am told you can do that with headers but how? Quote Link to comment https://forums.phpfreaks.com/topic/5227-headers-questions/ Share on other sites More sharing options...
hitman6003 Posted March 18, 2006 Share Posted March 18, 2006 [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. Quote Link to comment https://forums.phpfreaks.com/topic/5227-headers-questions/#findComment-18581 Share on other sites More sharing options...
holowugz Posted March 18, 2006 Author Share Posted March 18, 2006 doe that mean the file has to be in the same directory as ths script? Quote Link to comment https://forums.phpfreaks.com/topic/5227-headers-questions/#findComment-18655 Share on other sites More sharing options...
hitman6003 Posted March 18, 2006 Share Posted March 18, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/5227-headers-questions/#findComment-18661 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.