ScottDuncan
12-08-2004, 03:00 PM
Need PHP script help. Anybody have it or know where to find it?
I need a successful download from a click of a download button.
this is a link to my under construction website.
homemadebyx.com (http://digitallyoverwhelmed.com)
If you click one of the "files" buttons, it takes you to a dynamic
listing page with download buttons. If the filetype = .zip or .txt,
no problems. If the filetype = any other type, then the file is
corrupted in one way or another.
The .docs open in word with some sort of wacked code. The
.jpgs don't have a thumbnail or preview, in windows. The .mp3s
that previously had a image in the mp3 tag, doesn't work. The
mp3s also lock up Windows Media Player.
On button,
<a href="downloadFile.php?file=<? print "$currentDirectory/$fileName"; ?>
On download page,
$filename = $_GET['file'];
$file_extension = strtolower(substr(strrchr($filename,"."),1));
switch( $file_extension )
{
case "pdf": $ctype="application/pdf"; break;
case "exe": $ctype="application/octet-stream"; break;
case "zip": $ctype="application/zip"; break;
case "doc": $ctype="application/msword"; break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpeg":
case "jpg": $ctype="image/jpg"; break;
default: $ctype="application/force-download";
}
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Type: $ctype");
header("Content-Disposition: attachment; filename=".basename($filename).";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename));
readfile("$filename");
exit();
Any help would be extremely appreciated
ScottDuncan
x@homemadebyx.com
I need a successful download from a click of a download button.
this is a link to my under construction website.
homemadebyx.com (http://digitallyoverwhelmed.com)
If you click one of the "files" buttons, it takes you to a dynamic
listing page with download buttons. If the filetype = .zip or .txt,
no problems. If the filetype = any other type, then the file is
corrupted in one way or another.
The .docs open in word with some sort of wacked code. The
.jpgs don't have a thumbnail or preview, in windows. The .mp3s
that previously had a image in the mp3 tag, doesn't work. The
mp3s also lock up Windows Media Player.
On button,
<a href="downloadFile.php?file=<? print "$currentDirectory/$fileName"; ?>
On download page,
$filename = $_GET['file'];
$file_extension = strtolower(substr(strrchr($filename,"."),1));
switch( $file_extension )
{
case "pdf": $ctype="application/pdf"; break;
case "exe": $ctype="application/octet-stream"; break;
case "zip": $ctype="application/zip"; break;
case "doc": $ctype="application/msword"; break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpeg":
case "jpg": $ctype="image/jpg"; break;
default: $ctype="application/force-download";
}
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Type: $ctype");
header("Content-Disposition: attachment; filename=".basename($filename).";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename));
readfile("$filename");
exit();
Any help would be extremely appreciated
ScottDuncan
x@homemadebyx.com