[Plugin: W3 Total Cache] Download script fails because of W3-Total-Cache
-
I’m have a simple download script that fails if W3-Total-Cache is enabled. No matter what I do, my content-length setting is ignored and the download fails after a few bytes. It seems like W3-Total-Cache sends its own content-length header which seems to be why mine is ignored (usually set to 0).
I plan on extending this script for user permissions, etc. and therefore I need some wordpress functions. When I remove the line to load wordpress everything works as it should.
The usage of this code is:
yoursite.com/download.php?file=yourfile
<?php date_default_timezone_set('Europe/Paris'); // Load WordPress. require_once('wp-load.php'); $file = $_GET['file']; $info = pathinfo($file); $ext = $info['extension']; switch ($ext) { case "gif": $ctype="image/gif"; break; case "jpeg": case "jpg": $ctype = "image/jpg"; break; case "png": $ctype = "image/png"; break; case "pdf": $ctype = "application/pdf"; break; case "zip": $ctype = "application/zip"; break; case "txt": $ctype = "text/plain"; break; default: $ctype = "x-type/subtype"; } if (file_exists($file)) { $size = filesize($file); header("Content-Length: " . $size); header("Content-Type: " . $ctype); header("Content-Disposition: attachment; filename=" . $filename); ob_end_clean(); readfile($file); exit(); } else { die("ERROR: File doesn't exist!"); }
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘[Plugin: W3 Total Cache] Download script fails because of W3-Total-Cache’ is closed to new replies.