• 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)
  • Plugin Contributor Frederick Townes

    (@fredericktownes)

    Are you still having this issue? I believe excluding that file by adding it to the never cache the following pages field on the page cache settings tab is the remedy.

    Thread Starter MHagemeister

    (@mhagemeister)

    Thanks for your reply.

    I added my file to the “never cache the following pages” field, but still no success. W3 Total Cache still sends its own headers.

    Plugin Contributor Frederick Townes

    (@fredericktownes)

    If you disable all caching types on the general settings tab, the issue still occurs?

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.