jim.davidson Posted March 21, 2008 Share Posted March 21, 2008 I need some help I have a web site, we'll call it mysite.com mysite has the usual folders www images documents bolt loads.xls flash CssFiles I want to download "bolt loads.xls" from a site's documents folder. I have the following program that works fine when I'm testing locally. But I'm at a loss as to how to set the path for the web site I've tried the following nothing works $getfile = 'bolt loads.xls' $filepath = 'http://mysite.com/www/documents/'.$getfile; $filepath = '/www/documents/'.$getfile; $filepath = '/documents/'.$getfile; Here's the code i'm running <?php // Block any attemp to explore the filesystem if (isset($_GET['file']) && basename($_GET['file']) == $_GET['file']) { $getfile = $_GET['file']; } else { $getfile = NULL; } // define error handling $nogo = 'Sorry, download unavailable. <a href="download_bolt.php">Back</a>.'; if (!$getfile) { // go no further if filename not set echo $nogo; } else { // define the path name to the file // here is where I'm lost $filepath = 'http://mysite.com/www/documents/'.$getfile; // check that it exist and is readable if (file_exists($filepath) && is_readable($filepath)) { // get the file's size and send the appropriate headers $size = filesize($filepath); header('Content-Type: application/octet-stream'); header('Content-Length: '.$size); header('Content-Disposition: attachment; filename='.$getfile); header('Content-Transfer-Encoding: binary'); // open the file in binary read-only mode // suppress error messages if the file can't be opened $file = @ fopen($filepath, 'rb'); if ($file) { // stream the file and exit the script when complete fpassthru($file); exit; } else { echo $nogo; } } else { echo $nogo; echo $filepath; } } ?> Link to comment https://forums.phpfreaks.com/topic/97251-could-use-some-help-with-settinf-download-file-path/ Share on other sites More sharing options...
Rohan Shenoy Posted March 21, 2008 Share Posted March 21, 2008 $filepath = 'http://mysite.com/www/documents/'.$getfile; try removing the www/. So it should be $filepath = 'http://mysite.com/documents/'.$getfile; Link to comment https://forums.phpfreaks.com/topic/97251-could-use-some-help-with-settinf-download-file-path/#findComment-497638 Share on other sites More sharing options...
Rohan Shenoy Posted March 21, 2008 Share Posted March 21, 2008 and remember to change that everywhere. Link to comment https://forums.phpfreaks.com/topic/97251-could-use-some-help-with-settinf-download-file-path/#findComment-497639 Share on other sites More sharing options...
jim.davidson Posted March 21, 2008 Author Share Posted March 21, 2008 I just tried that and it doesn't work Link to comment https://forums.phpfreaks.com/topic/97251-could-use-some-help-with-settinf-download-file-path/#findComment-497648 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.