jeppers Posted July 18, 2007 Share Posted July 18, 2007 <?php // force to download a file // ex, ( [url=http://localhost/php/download.php?file=C:/Apache]http://localhost/php/download.php?file=C:/Apache[/url] Group/Apache2/hongkong.php ) // hope this can save your time :-) $file = $_REQUEST['file']; header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/force-download"); header( "Content-Disposition: attachment; filename=".basename($file)); header( "Content-Description: File Transfer"); @readfile($file); ?> can any one help i need to direct this code to a file which i want to download any ideas at the moment it just downloads a blank document and i am not sure on how to change the outcome Link to comment https://forums.phpfreaks.com/topic/60590-just-found-this/ Share on other sites More sharing options...
The Little Guy Posted July 18, 2007 Share Posted July 18, 2007 I don't know if this will help you at all, but this is what I use: <?php if (isset($_GET['filename'])){ header('Content-Type: application/octet-stream'); // what the file will be called header("Content-Disposition: attachment; filename=".$_GET['filename'].";"); // It the file will be named when it is down loaded readfile(str_replace('|||||',' ',$_GET['filename'])); }else{ } ?> Link to comment https://forums.phpfreaks.com/topic/60590-just-found-this/#findComment-301413 Share on other sites More sharing options...
jeppers Posted July 18, 2007 Author Share Posted July 18, 2007 not sure what to with it i have changes the file name as you can see down below and then i tried to load it and nothing... is it supposed to come up with a box asking me if i would like to save it... please help as i am a little slow Link to comment https://forums.phpfreaks.com/topic/60590-just-found-this/#findComment-301419 Share on other sites More sharing options...
The Little Guy Posted July 18, 2007 Share Posted July 18, 2007 you will need to save that code in a file such as download.php, then link to that file using the full path name, so it would looks something like this: http://mysite.com/download.php?filename=/this/is/my/file.jpg Link to comment https://forums.phpfreaks.com/topic/60590-just-found-this/#findComment-301461 Share on other sites More sharing options...
jeppers Posted July 19, 2007 Author Share Posted July 19, 2007 so when it is in the fil all i have to do is create a link to that code on the website and then it will download the file required.. is that correct Link to comment https://forums.phpfreaks.com/topic/60590-just-found-this/#findComment-302162 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.