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 Quote Link to comment 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{ } ?> Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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.