Source for file getFile.act.php

Documentation is available at getFile.act.php

  1. <?php
  2. /**
  3. * @since 12/12/06
  4. * @package polyphony.export
  5. *
  6. * @copyright Copyright &copy; 2005, Middlebury College
  7. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  8. *
  9. * @version $Id: getFile.act.php,v 1.3 2007/09/19 14:04:55 adamfranco Exp $
  10. */
  11.  
  12. require_once(POLYPHONY."/main/library/AbstractActions/Action.class.php");
  13.  
  14.  
  15. /**
  16. * Give the user the file that they wish to download
  17. *
  18. * @since 12/12/06
  19. * @package polyphony.export
  20. *
  21. * @copyright Copyright &copy; 2005, Middlebury College
  22. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  23. *
  24. * @version $Id: getFile.act.php,v 1.3 2007/09/19 14:04:55 adamfranco Exp $
  25. */
  26. class getFileAction
  27. extends Action
  28. {
  29. /**
  30. * Execute the action
  31. *
  32. * @return void
  33. * @access public
  34. * @since 12/12/06
  35. */
  36. function execute () {
  37. $harmoni = Harmoni::instance();
  38. $harmoni->request->startNamespace('export');
  39. $file = urldecode(RequestContext::value('file'));
  40. $harmoni->request->endNamespace();
  41. // Check that this is a valid file to return. We don't want to give them
  42. // any file on the system.
  43. if (!is_array($_SESSION['EXPORTED_FILES'])
  44. || !isset($_SESSION['EXPORTED_FILES'][$file])
  45. || !is_array($_SESSION['EXPORTED_FILES'][$file]))
  46. {
  47. print "<h2>"._("Download Error")."</h2>";
  48. print "<p>"._("This download is not currently available. It may have been already downloaded and removed.")."</p>";
  49. print "<p style='margin: 10px; margin-left: 20px;'><a href='".$_SERVER['HTTP_REFERER']."'>"._("Download again")."</a></p>";
  50. print "<p style=''><a href='".$harmoni->request->quickURL("collections", "namebrowse")."'>"._("&lt;-- Return")."</a></p>";
  51. print "<hr/>";
  52. throwError(new Error($file." is not in the allowed list to download.", "Exporter"));
  53. }
  54. header("Content-type: ".$_SESSION['EXPORTED_FILES'][$file]['mime']);
  55. header('Content-Disposition: attachment; filename="'.
  56. $_SESSION['EXPORTED_FILES'][$file]['name'].'"');
  57. header('Content-Length: ' . filesize($_SESSION['EXPORTED_FILES'][$file]['file']));
  58. // clean all output buffers
  59. while (ob_get_level())
  60. ob_end_clean();
  61. $handle =fopen($_SESSION['EXPORTED_FILES'][$file]['file'], "rb");
  62. while (!feof($handle)) {
  63. set_time_limit(0);
  64. print fread($handle, 8192);
  65. flush();
  66. @ob_flush();
  67. }
  68. fclose($handle);
  69. unlink($_SESSION['EXPORTED_FILES'][$file]['file']);
  70. unset($_SESSION['EXPORTED_FILES'][$file]);
  71. exit;
  72. }
  73. }
  74.  
  75. ?>

Documentation generated on Wed, 19 Sep 2007 10:23:23 -0400 by phpDocumentor 1.3.0RC3