SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict Viral's Avatar
    Join Date
    Nov 2001
    Location
    Washington DC
    Posts
    294
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Generate downloadable (inline) text file?

    Guys,

    I need to generate a text file inline from my code. I know how to generate a downloadable file using an external php script, like this...
    PHP Code:
    <? //Generate text file on the fly - text.php
     
    header("Content-type: text/plain");
    header("Content-Disposition: attachment; filename=savethis.txt");
     
    // do your Db stuff here to get the content into $content
    print "This is some text...\n";
    print 
    $content;
    ?> 
     
    <a href="text.php">Download me</a>
    But I have a very intensive script that does a lot of processing and takes a long time. So what I'd like is to avoid having to do it twice. Anyone know how to do something like this?
    PHP Code:
    <?
    // contact the DB and get lots of info and parse it into $content
    print "<html><body>
    Read it here<br>
    $content<br>
    or download it"
    ;
     
    //generate the downloadable version here somehow => $contentfile
    print "<a href="$contentfile">Here!</a></body></html>";
    ?>
    this would basically be generating a file in memory without having to write a temp file, but do it without having to call an external php script.
    Anyone tried something like this before? Help...

    --Viral
    A computer without Windows is like a chocolate cake without mustard.

  2. #2
    Super Ninja Monkey Travis's Avatar
    Join Date
    Dec 2001
    Location
    Sioux City, Iowa
    Posts
    691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well if you need it in memory I believe the semaphore extension would help you out. However, I would recommend a good cache class to either handle the memory or save temp files to a local directory.
    Travis Watkins - Hyperactive Coder
    My Blog: Realist Anew
    Projects: Alacarte - Gnome Menu Editor

  3. #3
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i wouldn't use the shared mem functions since they're not that available (and might not be good if the stuff is large). i'd just cache the stuff in a flat file.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  4. #4
    SitePoint Addict Viral's Avatar
    Join Date
    Nov 2001
    Location
    Washington DC
    Posts
    294
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Indeed. I've given up on this and simply dumped the necessary chunk to a text file. This was always a backup plan, but I wanted to avoid it if possible. Oh well, no big deal...

    --Viral
    A computer without Windows is like a chocolate cake without mustard.


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
  •