Title: W3 Total Cache &amp; PHP readfile function
Last modified: August 19, 2016

---

# W3 Total Cache & PHP readfile function

 *  [Barret Ruttan](https://wordpress.org/support/users/capn-code/)
 * (@capn-code)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/w3-total-cache-amp-php-readfile-function/)
 * Hi Frederick,
 * The following code snippet, from the [PHP](http://ca.php.net/manual/en/function.readfile.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.
 * [http://wordpress.org/extend/plugins/w3-total-cache/](http://wordpress.org/extend/plugins/w3-total-cache/)

Viewing 9 replies - 1 through 9 (of 9 total)

 *  [Frederick Townes](https://wordpress.org/support/users/fredericktownes/)
 * (@fredericktownes)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/w3-total-cache-amp-php-readfile-function/#post-1346963)
 * The flush() is likely the issue, try commenting that out.
 *  Thread Starter [Barret Ruttan](https://wordpress.org/support/users/capn-code/)
 * (@capn-code)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/w3-total-cache-amp-php-readfile-function/#post-1347024)
 * 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.
 *  [Frederick Townes](https://wordpress.org/support/users/fredericktownes/)
 * (@fredericktownes)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/w3-total-cache-amp-php-readfile-function/#post-1347032)
 * Also remove: `ob_clean();`
 *  Thread Starter [Barret Ruttan](https://wordpress.org/support/users/capn-code/)
 * (@capn-code)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/w3-total-cache-amp-php-readfile-function/#post-1347035)
 * Same result. Mind you, I’m using 0.8.5, not 0.8.5.1.
 *  [Frederick Townes](https://wordpress.org/support/users/fredericktownes/)
 * (@fredericktownes)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/w3-total-cache-amp-php-readfile-function/#post-1347036)
 * Why aren’t you using the latest version? Where are you using this code? In a 
   template? Which one?
 *  Thread Starter [Barret Ruttan](https://wordpress.org/support/users/capn-code/)
 * (@capn-code)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/w3-total-cache-amp-php-readfile-function/#post-1347039)
 * 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?
 *  [Frederick Townes](https://wordpress.org/support/users/fredericktownes/)
 * (@fredericktownes)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/w3-total-cache-amp-php-readfile-function/#post-1347040)
 * 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](https://wordpress.org/support/users/capn-code/)
 * (@capn-code)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/w3-total-cache-amp-php-readfile-function/#post-1347041)
 * Okay, thanks for the advice, Frederick.
 *  [Frederick Townes](https://wordpress.org/support/users/fredericktownes/)
 * (@fredericktownes)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/w3-total-cache-amp-php-readfile-function/#post-1347042)
 * No problem.

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘W3 Total Cache & PHP readfile function’ is closed to new replies.

 * 9 replies
 * 2 participants
 * Last reply from: [Frederick Townes](https://wordpress.org/support/users/fredericktownes/)
 * Last activity: [16 years, 4 months ago](https://wordpress.org/support/topic/w3-total-cache-amp-php-readfile-function/#post-1347042)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
