W3 Total Cache
Download script fails because of W3-Total-Cache (4 posts)

  1. MHagemeister
    Posted 5 years ago #

    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:


    // Load WordPress.
    $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);
    } else {
    	die("ERROR: File doesn't exist!");
  2. Frederick Townes
    Plugin Author

    Posted 5 years ago #

    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.

  3. MHagemeister
    Posted 5 years ago #

    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.

  4. Frederick Townes
    Plugin Author

    Posted 5 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • W3 Total Cache
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic