Help save net neutrality! Learn more.

fetch files after form submission

  • jensw

    jensw - 2005-09-14

    I have to download a lot of excel files from a system with statistical data. Normally I have to setup the desired contents of the file in a form and after pressing submit the files is downloaded (meaning the broswer shows the download dialog).

    Now I would like to automate this process. I got everything working from login to form submission, but now i'm stuck how to get the excel file with snoopy, cause all I get is the html but not the excel file.

    Any hints?

    Thanks in advance

    • tgknight

      tgknight - 2005-10-02

      I'm interested in doing somewhat of the same thing.  I need to retrieve a file for the user after form submission.

      One possibility would be to detect the name of the page that is posted to and redirect the file at the beginning of your script to the user.

      I guess you would want to do the check at the beginning of your script before any HTML is output.

      One trick that might help is to insert a hidden form field into the form that your are submitting from and detect that variable upon submission.

      I usesome regular expressions to detect the form I am looking for and alter the output to includ the hidden field.

    • tgknight

      tgknight - 2005-10-12

      I have successfully completed this after much experimentation... Basically I used a regular expression to parse the URL before outputting anything, and if the condition matches what I know to be a file download URL then instead of displaying my normal page, I output download headers.

          // Force download via headers
          header('Pragma: private');
          header('Cache-control: private, must-revalidate');
          header('Content-Disposition: attachment; filename="'.$reportname.'";');
          header("Content-Type: $ctype");

      This will force a download box.. .then you just output as normal.

          // Output results to file and stop processing
          print $snoopy->results;

      Good luck :)


Log in to post a comment.