daemonkin
08-20-2007, 04:49 PM
Hi guys,
Trying to use PHP to download a pdf from server to local machine.
Got the following:
$bs = Singleton::getInstance('BrowserSniffer');
$file = $_SERVER['DOCUMENT_ROOT'] . '/pdf/' . $location;
$filename = substr(strrchr($file, '/'), 1);
if ($bs->name == 'Mozilla') {
$content_type = "application/octet-stream\n";
$attachment = ' attachment; ';
} else {
$content_type = "application/download\n";
$attachment = ' ';
}
header('Content-Type: ' . $content_type);
header('Content-Transfer-Encoding: binary');
header('Content-Disposition: ' . $attachment . ' filename=' . $filename);
header('Content-Length: ' . filesize($file));
$fn = fopen($file, 'r');
fpassthru($fn);
But cannot get the file to download if $location has spaces. Is there any way around this?
D.
Trying to use PHP to download a pdf from server to local machine.
Got the following:
$bs = Singleton::getInstance('BrowserSniffer');
$file = $_SERVER['DOCUMENT_ROOT'] . '/pdf/' . $location;
$filename = substr(strrchr($file, '/'), 1);
if ($bs->name == 'Mozilla') {
$content_type = "application/octet-stream\n";
$attachment = ' attachment; ';
} else {
$content_type = "application/download\n";
$attachment = ' ';
}
header('Content-Type: ' . $content_type);
header('Content-Transfer-Encoding: binary');
header('Content-Disposition: ' . $attachment . ' filename=' . $filename);
header('Content-Length: ' . filesize($file));
$fn = fopen($file, 'r');
fpassthru($fn);
But cannot get the file to download if $location has spaces. Is there any way around this?
D.