membership call is preventing readfile() somehow

By markr - August 6, 2014

This readfile() procedure works fine until I add the viewer and login lines for membership. Then the file become corrupted (or something) and won't display.

Can you think of why securing the page is messing with the latter code? See any options I could try to unfetter the readfile() ?

require_once '/myhost/public_html/cmsAdmin/lib/viewer_functions.php';
if (!$CURRENT_USER) {websiteLogin_redirectToLogin();}

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/pdf');
    header('Content-Disposition: inline; 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;
    } // endif

By gregThomas - August 14, 2014

Hi Markr,

Is an error message displayed at all?

I'm wondering if the server can't add the headers, as the page has already started loading. This can happen if you have any white space between your PHP opening tag and the start of the document, for example:

  
 <?php //white space at start of document

as opposed to

<?php // no white space at start

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com