22-09-2007, 20:23
|
|
|
חבר מתאריך: 19.03.07
הודעות: 75
|
|
אחרי שהלכתי הרבה מכות עם הקוד שלי כדי לתמוך בכל השטויות האלה כמו שצריך...
שים לב שהכל נעשה בheaders, כלומר אסור לך לשלוח שום דבר לפני קטע הקוד הזה.
הנה, קח -
קוד PHP:
$file_extension = strtolower(substr(strrchr($dnloadLink,"."),1)); $file_name = "res/" .substr(strrchr($dnloadLink,"/"),1); $AgetHeaders = @get_headers($dnloadLink); if (preg_match("|200|", $AgetHeaders[0])) { // file exists } else { $warning = "<BR> Download FAILED \n" ."<P> Error - " .__line__ ."</P>"; printHTML_NODATA($warning, $me_user); exit; } switch( $file_extension ) { case "pdf": $ctype="application/pdf"; 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 "dwg": $ctype="application/acad"; break; case "mcd": $ctype="application/mcad"; 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"); // required header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: private",false); // required for certain browsers header("Content-Type: $ctype"); header("Content-Disposition: attachment; filename=\"".basename($file_name)."\";" ); header("Content-Transfer-Encoding: binary"); header("Content-Length: ".filesize($file_name)); readfile("$file_name");
|