• Hi Frederick,

    The following code snippet, from the PHP website(Example #1, under Examples), work as expected when the W3 Total Cache plugin is activated enabled or disabled, on a clean WordPress install:

    <?php
    $file = ‘monkey.gif’;

    if (file_exists($file)) {
    header(‘Content-Description: File Transfer’);
    header(‘Content-Type: application/octet-stream’);
    header(‘Content-Disposition: attachment; filename=’.basename($file));
    header(‘Content-Transfer-Encoding: binary’);
    header(‘Expires: 0’);
    header(‘Cache-Control: must-revalidate, post-check=0, pre-check=0’);
    header(‘Pragma: public’);
    header(‘Content-Length: ‘ . filesize($file));
    ob_clean();
    flush();
    readfile($file);
    exit;
    }
    ?>

    Hoping you may be able to shed some light on the situation.

    https://www.ads-software.com/extend/plugins/w3-total-cache/

Viewing 9 replies - 1 through 9 (of 9 total)
  • The flush() is likely the issue, try commenting that out.

    Thread Starter Barret Ruttan

    (@capn-code)

    Thank you for your timely – much appreciated – reply, Frederick.

    I tried your suggestion to no avail(file is empty); whereas, if I disable the plugin, the file is the correct size.

    Also remove: ob_clean();

    Thread Starter Barret Ruttan

    (@capn-code)

    Same result. Mind you, I’m using 0.8.5, not 0.8.5.1.

    Why aren’t you using the latest version? Where are you using this code? In a template? Which one?

    Thread Starter Barret Ruttan

    (@capn-code)

    That would probably be a good idea. ??

    I’m testing on a fresh WordPress 2.9.1 install, W3 Total Cache 0.8.5.1, default template. It works for smaller files(less than 1MB); but not for larger files(10 MB) – instead they are empty.

    I’m wondering if it has something to do with the buffer?

    That’s a possibility, but since this is not my code, I’m only trying to answer your questions as a courtesy. Outside of avoiding the use of ob_ and flush() which interfere with most caching plugins, that’s as much as I can suggest in this case. If what you’re trying to do is set headers on images for download or something similar it’s likely best to write a function for functions.php and avoid trying to implement this stuff directly in a template.

    Thread Starter Barret Ruttan

    (@capn-code)

    Okay, thanks for the advice, Frederick.

    No problem.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘W3 Total Cache & PHP readfile function’ is closed to new replies.