Professional Web Applications Themes

This is my fourth day of hitting this brick wall! Anyone...Purleeeeese help! - PHP Development

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 ...

  1. #1

    Default This is my fourth day of hitting this brick wall! Anyone...Purleeeeese help!

    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.
    [url]http://www.violasystems.com[/url]
    [email]stephen.jacksonviolasystems.com[/email]
    Mobile +358 50 343 5159
    Steve Jackson Guest

  2. #2

    Default Re: [PHP] This is my fourth day of hitting this brick wall! Anyone...Purleeeeese help!

    also, here is a good one to try.

    build yourself an error doent that gets called when a file that cannot
    befound is looked for.

    Then in this error doent, you perform a check on the file/script name
    that was called. If it happens to end with .pdf, then you could assume that
    it is going to be a pdf that needs to be displayed. Then you get the name
    of the file called and look for it in your directory that contains all your
    pdf's. If you find a file in there by the same name, then you can use
    readfile or some other file reader to pass the file through.

    This should take care of the problem. You might also need to send back some
    specific headers to tell the browser what you are sending it, but it should
    work even without that being done.

    Jim Lucas

    ----- Original Message -----
    From: "Jason Wong" <php-generalgremlins.biz>
    To: <php-generallists.php.net>
    Sent: Thursday, September 18, 2003 2:01 AM
    Subject: Re: [PHP] This is my fourth day of hitting this brick wall!
    Anyone...Purleeeeese help!

    > On Thursday 18 September 2003 16:24, Steve Jackson wrote:
    > > 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.
    >
    > [snip]
    >
    > Have you tried the obvious, such as using browsers other than IE? Or a
    > different version of IE?
    >
    > Fact is that there are versions of IE that have broken mime handling.
    >
    > --
    > Jason Wong -> Gremlins Associates -> www.gremlins.biz
    > Open Source Software Systems Integrators
    > * Web Design & Hosting * Internet & Intranet Applications Development *
    > ------------------------------------------
    > Search the list archives before you post
    > http://marc.theaimsgroup.com/?l=php-general
    > ------------------------------------------
    > /*
    > modem, adj.:
    > Up-to-date, new-fangled, as in "Thoroughly Modem Millie." An
    > unfortunate byproduct of kerning.
    >
    > [That's sic!]
    > */
    >
    > --
    > PHP General Mailing List (http://www.php.net/)
    > To unsubscribe, visit: http://www.php.net/unsub.php
    >
    >
    Jim Lucas Guest

  3. #3

    Default Re: [PHP] This is my fourth day of hitting this brick wall! Anyone...Purleeeeesehelp!

    Jim Lucas wrote:
    > This should take care of the problem. You might also need to send back some
    > specific headers to tell the browser what you are sending it, but it should
    > work even without that being done.
    I think this works only in IE, always send Content-Type.
    Marek Kilimajer Guest

Similar Threads

  1. ASPNET and NETWORK SERVICE accounts hitting SQL Server
    By Jim Moon in forum ASP.NET Security
    Replies: 2
    Last Post: June 30th, 09:32 PM
  2. Hit a brick wall
    By Mark Gibson in forum Macromedia Flash Sitedesign
    Replies: 5
    Last Post: January 8th, 03:49 PM
  3. Replies: 0
    Last Post: September 18th, 10:32 AM
  4. Replies: 0
    Last Post: July 24th, 08:08 PM
  5. Layer Style Brick Texture
    By Jeffrey Hanson in forum Adobe Photoshop Elements
    Replies: 3
    Last Post: July 23rd, 08:49 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139