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 three $filepath and nothing works!
$getfile = 'bolt loads.xls'
$filepath = 'http://mysite.com/www/documents/'.$getfile;
$filepath = '/www/documents/'.$getfile;
$filepath = '/documents/'.$getfile;
Here's the code
<?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;
}
}
?>
Any help would be appreciated