Friends.
I am doing a file manager application.
I did the upload part.
now doing the download script.
<?php
$path = $_SERVER['DOCUMENT_ROOT']."/path2file/"; // play with the path if the document root does noet exist
$fullPath = $path.$_GET['download_file'];
if ($fd = fopen ($fullPath, "r")) {
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
$ext = strtolower($path_parts["extension"]);
switch ($ext) {
case "pdf":
header("Content-type: application/pdf"); // add here more headers for diff. extensions
header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); // use 'attachement' to force a download
break;
default;
header("Content-type: application/octet-stream");
header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
}
header("Content-length: $fsize");
header("Cache-control: private"); //use this to open files directly
while(!feof($fd)) {
$buffer = fread($fd, 2048);
echo $buffer;
}
}
fclose ($fd);
exit;
// example: place this kind of link into your document where the download is shown:
// <a href="download.php?download_file=some_file.pdf">Do wnload here</a>
?>
I got from http://www.finalwebsites.com/snippets.php?id=4
The file downloads perfectly.
but, can not open any file.
For example, if the downloaded file is "sample.jpg", I can not open it with any image viewer or firefox.
but the file size is same as the original.
how to solve this problem?
thanks,
T.Shrinivasan.