I know a few have already done this on the list but I have read articles
on Zend tried other functions done everything I can, de-bugged till I'm
blue in the face and still haven't been able to solve this.

I need to protect files by leaving them outside the web root.
I call them up ok. (the link is get.php?file=EventNotifcation_01.pdf)
I can download the file fine by right clicking the link in the browser
and saving it to disk.
My problem is I can't view it inline. IE in the browser. It's a PDF file
so I should be able to.
This is the code that processes:

<? 
// path to file outside of root.    
define('FILEDIR', '/home/.sites/144/site281/downloads/'); 
$path = FILEDIR . $file; 
//check that this file exists and that it doesn't include 
//any special characters 
    if(!is_file($path) OR !eregi('^[A-Z_0-9][A-Z_0-9.]*$', $file)) 
    { 
        header("Location: error.php"); 
        exit(); 
    } 

    /* 
    ** //check that the user has permission to download file 
    ** if(user does not have permission) 
    ** { 
    **     //redirect to error page 
    **     header("Location: error.php"); 
    **     exit(); 
    ** } 
    */ 

        // get the extension of the file

        $p = explode('.', $file);
        $extension = $p[sizeof($p)-1];
        switch ($extension)
        {
        // define headers depending on $extension variable.
        case "pdf" :
        header("Content-type: application/pdf");
        header("Content-disposition: inline;
filename=\"".basename($file));
        break;
        case "txt" :
        header("Content-type: text/plain");
        header("Content-disposition: inline;
filename=\"".basename($file));
        break;
        default :
        // force download dialog if no extension defined.
        header("Content-type: application/octet-stream"); 
        header("Content-disposition: attachment; filename=\"$file\"");
        break; 
        }
        header("Content-transfer-encoding: binary"); 
      header("Content-length: " . filesize($path));
      header("Cache-control: must-revalidate"); 
        //send file contents 
      $fp=fopen($path, "r"); 
        fpassthru($fp);
        // debug - remove the headers and test output vars. 
        /*echo "Extension is $extension";
        echo "<br>File is $file";
        echo "<br>p is $p";
        echo "<br>path is $path";
        echo "<br>FP is $fp";*/
?> 

Echoing the vars results in:
Extension is pdf
File is EventNotification_01.pdf
P is Array
Path is /home/.sites/144/site281/downloads/EventNotification_01.pdf
FP is Resource is #1

Has anyone got any clue what the problem is? 


Steve Jackson
Web Development and Marketing Manager
Viola Systems Ltd.
http://www.violasystems.com
[EMAIL PROTECTED]
Mobile +358 50 343 5159

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to