Answers.Body: <p>The 4th parameter to <a href="http://buildwithcraft.com/classreference/services/HttpRequestService#sendFile-detail" rel="nofollow">HttpRequestService->sendFile()</a> is <code>$terminate = true</code>, which will by default, terminate the request after the file is sent.</p>
  
  <p>Set that to <code>false</code> and let the request continue as usual and you should be set.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-23T20:24:26.460Z
Answers.Text: Thanks Brad, but I did have it set to false.  I tried changing it to true, just to see, and it throws an error:
  
    "File not found
    Firefox can't find the file at /admin/entries/videoGroup/4-videotest."
Answers.UserDisplayName: Mason
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-23T20:35:42.823Z
Answers.Text: What if you call `$this->redirectToPostedUrl()` from your controller after the file is sent?
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-23T23:02:16.257Z
Answers.Text: No luck with that yet, but I'll keep tweaking and post back if I get a working solution.  Thanks!
Answers.UserDisplayName: Mason
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-22T22:48:03.823Z
Answers.LastActivityDate: 2015-04-22T22:48:03.823Z
Answers.UserDisplayName: Brad Bell
Body: <p>I'm writing a plugin that gathers up all the assets from an entry and saves it out as a zip (along with a JSON file with information from the entry).  Any advice regarding a better method is appreciated, but right now I add the code in on('entries.saveEntry'), like so:</p>
  
  <pre><code>    craft()-&gt;on('entries.saveEntry', function(Event $event) {
          $entry = $event-&gt;params['entry'];
          $outputArray = array();
  
          /* 
          business logic filling variables removed for the sake of brevity 
          */
  
          if (($entry['sectionId'] == 3) &amp;&amp; ($entry['buildPage'] == 1)) {
              file_put_contents(getcwd()."/build/videos.json", json_encode($outputArray));
  
              $assetGroup[] = getcwd()."/build/videos.json";
              $zipfile = craft()-&gt;buildPage-&gt;create_zip($assetGroup, $entry['uri'], getcwd()."/build/");
              $filename = substr($zipfile,strrpos($zipfile,'/')+1);
  
              if (file_exists($zipfile)) {
                  craft()-&gt;request-&gt;sendFile($filename, file_get_contents( $zipfile ), array('forceDownload' =&gt; true), false);
              }
          }
      });
  </code></pre>
  
  <p>Everything works, except that my sendFile call prevents the user from being returned to the Entries page (or stating a new entry, etc.), if that was their intent.  Is it possible to capture where they were headed before I stopped them, so that I can send them on their way?  Or is that not possible the way I have things written?</p>
  
Tags: <plugin-development><entries><plugins><php>
Title: Can I capture the users intent ('Save' vs 'Save and continue editing') for craft()->on('entries.saveEntry'
ThreadText: # Can I capture the users intent ('Save' vs 'Save and continue editing') for craft()->on('entries.saveEntry'
  
  (Asked by: username_0 on 2015-04-22)
  
  I'm writing a plugin that gathers up all the assets from an entry and saves it out as a zip (along with a JSON file with information from the entry). Any advice regarding a better method is appreciated, but right now I add the code in on('entries.saveEntry'), like so:
  
  ```
      craft()->on('entries.saveEntry', function(Event $event) {
          $entry = $event->params['entry'];
          $outputArray = array();
  
          /* 
          business logic filling variables removed for the sake of brevity 
          */
  
          if (($entry['sectionId'] == 3) && ($entry['buildPage'] == 1)) {
              file_put_contents(getcwd()."/build/videos.json", json_encode($outputArray));
  
              $assetGroup[] = getcwd()."/build/videos.json";
              $zipfile = craft()->buildPage->create_zip($assetGroup, $entry['uri'], getcwd()."/build/");
              $filename = substr($zipfile,strrpos($zipfile,'/')+1);
  
              if (file_exists($zipfile)) {
                  craft()->request->sendFile($filename, file_get_contents( $zipfile ), array('forceDownload' => true), false);
              }
          }
      });
  
  ```
  
  Everything works, except that my sendFile call prevents the user from being returned to the Entries page (or stating a new entry, etc.), if that was their intent. Is it possible to capture where they were headed before I stopped them, so that I can send them on their way? Or is that not possible the way I have things written?
  
  **Tags:** plugin-development, entries, plugins, php
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-04-22. Score: 2
  
  The 4th parameter to [HttpRequestService->sendFile()](http://buildwithcraft.com/classreference/services/HttpRequestService#sendFile-detail) is `$terminate = true`, which will by default, terminate the request after the file is sent.
  
  Set that to `false` and let the request continue as usual and you should be set.
  
  > **Comments:**
  > **username_0**: Thanks username_1, but I did have it set to false.  I tried changing it to true, just to see, and it throws an error:    "File not found   Firefox can't find the file at /admin/entries/videoGroup/4-videotest."  
  > **username_1**: What if you call `$this->redirectToPostedUrl()` from your controller after the file is sent?  
  > **username_0**: No luck with that yet, but I'll keep tweaking and post back if I get a working solution.  Thanks!  
  
  ---
  
  