SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    Confirmed Halfwit
    Join Date
    Oct 1999
    Location
    Vancouver, BC, Canada
    Posts
    983
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm trying to output a .pdf file to screen.. and I have the following code that does not work:
    Code:
    <?php
    
    header( "Content-Type: application/pdf" );
    include('config.php');
    
    session_start();
    
    $dir = '/home3/gridops/reports/henri/TSR/test.pdf';
    readfile("$dir");
    >?
    It does work if I remove the "session_start()" part. However, if I do this then I won't be able to set the $dir variable with my session values..

    Anyone have any idea's? Is there a different way to output a .pdf file to screen besides linking to it directly? (I don't want the user to see where the file is located, so I am throwing a bunch of variables into the session and then calling the page that has this script.)

    Thanks,
    Henri Straforelli
    Last edited by hstraf; May 10, 2001 at 15:48.
    - A simple online WYSIWYG editor for HTML code snippets.
    - Managed Web Hosting - $3.95/month (resellers welcome)
    - Why pay more? $8.95 domains & $9.95 SSL certificates!

  2. #2
    SitePoint Zealot cokeman's Avatar
    Join Date
    Dec 2000
    Location
    So. California
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure, but part of me feels that sessions might be like headers and have to be sent before any other content.. does config.php output anything? if so, maybe you could try moving the include() line to after the session_start()...

    of course, I might be totally off base here..

  3. #3
    One website at a time mmj's Avatar
    Join Date
    Feb 2001
    Location
    Melbourne Australia
    Posts
    6,282
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Cokeman you are right.

    session_start, or some function that implies session_start must occur before the headers are sent to the browser. This enables a cookie to be sent.

    It depends what is in your config.php script. Make sure there is no html, including whitespace before and after the <? ?> tags.
    Last edited by mmj; May 11, 2001 at 09:58.
    [mmj] My magic jigsaw
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The Bit Depth Blog Twitter Contact me
    Neon Javascript Framework Jokes Android stuff

  4. #4
    Confirmed Halfwit
    Join Date
    Oct 1999
    Location
    Vancouver, BC, Canada
    Posts
    983
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It depends what is in your config.php script. Make sure there is no html, including whitespace before and after the <? ?> tags.
    There is no HTML in the config.php script. The sample code I included in my original post actually doesn't work if the include is there or not.

    So does this mean it is impossible to use sessions, and still output a pdf file to screen?
    - A simple online WYSIWYG editor for HTML code snippets.
    - Managed Web Hosting - $3.95/month (resellers welcome)
    - Why pay more? $8.95 domains & $9.95 SSL certificates!

  5. #5
    midnight coder
    Join Date
    Dec 2000
    Location
    The flat edge of the world
    Posts
    838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    session start has to be in front before anything else, so see if this works:

    PHP Code:
    <?php
    session_start
    ();
    header"Content-Type: application/pdf" );
    include(
    'config.php');

    $dir '/home3/gridops/reports/henri/TSR/test.pdf';
    readfile("$dir");

    ?>

  6. #6
    Confirmed Halfwit
    Join Date
    Oct 1999
    Location
    Vancouver, BC, Canada
    Posts
    983
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nope. That didn't work either.

    The pdf file just gets displayed as straight "ascii".. in other words, all I see are the contents of the pdf file. The browser doesn't realize that it is a pdf file format and doesn't call the plug-in, etc..

    From what I can see.. it looks like sessions are incompatible with anything that requires header of Content Type.
    - A simple online WYSIWYG editor for HTML code snippets.
    - Managed Web Hosting - $3.95/month (resellers welcome)
    - Why pay more? $8.95 domains & $9.95 SSL certificates!


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
  •