Form->Results->Send Headers(Download)->Return Any ideas

Discussion in 'PHP' started by Big 'G', Mar 1, 2006.

  1. #1
    Hi, all
    I have a form, upload in this case, from this upload i perform some functions
    then generate a zip file to download sent via headers
    // We'll be outputting a zip
    header('Content-type: application/zip');
    header('Content-Disposition: attachment; filename=Download.zip');
    //
    readfile($p_zipname);
    Okay all this works fine, however the orginal page is static and needs to be refreshed. I dealy i want to display a results page after the zip is created and offered for donwload.
    I have tried ob_start and such but no joy, may be doing it wrong
    Can any provide any hints, tips, or best a sample script cant find anything on the net :mad:
    So to reflect in short hand this is what i have
    
    <?php
    if(isset($_POST['SUBMIT'])){
    //Perform Functions 
    ......
    //Send download
    header('Content-type: application/zip');
    header('Content-Disposition: attachment; filename=Download.zip');
    //
     readfile($p_zipname);
    // THIS IS THE PROBLEM BELOW
    echo Results
    }
    //Also this page stays statics still show the upload form with the file path in
    //Would like to get it reset also
    Main Upload page Details
    <form ......
    
    ?>
    
    Code (markup):
    Any ideas :confused:
     
    Big 'G', Mar 1, 2006 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Could you do something like creating the zip file for download, and not in the headers.

    Something like:

    Resuts here...
    Your Zip file is ready - Click to Download

    or do you need to display the results after the file is downloaded?
     
    jestep, Mar 1, 2006 IP
  3. Big 'G'

    Big 'G' Member

    Messages:
    89
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    48
    #3
    That was my original idea, but the zip if is private and created off the web root and could get it to access the zip, tried a few ways of accessing it with no luck.

    The results dont really need to be shown, just more to reresh the form looks wierd with it not resetting.
     
    Big 'G', Mar 1, 2006 IP
  4. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #4
    What if you have the form post to a result page with a unique key, and the result page generates the zip. Post to a new page and generate the zip there. If the form has errors, you can return them back to the form page.
     
    jestep, Mar 1, 2006 IP
  5. wwm

    wwm Peon

    Messages:
    308
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #5
    http://pear.php.net/package/Mail_Mime

    http://www.zend.com/pear/tutorials/Mail.php


    example sending text/html emails with attachments

    <?php
    include('Mail.php');
    include('Mail/mime.php');
    
    $text = 'Text version of email';
    $html = '<html><body>HTML version of email</body></html>';
    $file = '/home/richard/example.php';
    $crlf = "\n";
    $hdrs = array(
                  'From'    => 'you@yourdomain.com',
                  'Subject' => 'Test mime message'
                  );
    
    $mime = new Mail_mime($crlf);
    
    $mime->setTXTBody($text);
    $mime->setHTMLBody($html);
    $mime->addAttachment($file, 'text/plain');
    
    $body = $mime->get();
    $hdrs = $mime->headers($hdrs);
    
    $mail =& Mail::factory('mail');
    $mail->send('postmaster@localhost', $hdrs, $body);
    ?>
    PHP:
     
    wwm, Mar 1, 2006 IP