get.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. $RUNTIME_NOAPPS=true; //no need to load the apps
  3. $RUNTIME_NOSETUPFS=true; //don't setup the fs yet
  4. require_once '../../lib/base.php';
  5. OC_JSON::checkAppEnabled('files_sharing');
  6. require_once 'lib_share.php';
  7. //get the path of the shared file
  8. $token = $_GET['token'];
  9. $source = OC_Share::getSource($token);
  10. if ($source !== false) {
  11. // TODO Manipulating the string may not be the best choice. Is there an alternative?
  12. $user = substr($source, 1, strpos($source, "/", 1) - 1);
  13. OC_Util::setupFS($user);
  14. $source = substr($source, strlen("/".$user."/files"));
  15. $subPath = isset( $_GET['path'] ) ? $_GET['path'] : '';
  16. $root = $source;
  17. $source .= $subPath;
  18. if (!OC_Filesystem::file_exists($source)) {
  19. header("HTTP/1.0 404 Not Found");
  20. $tmpl = new OC_Template("", "404", "guest");
  21. $tmpl->assign("file", $subPath);
  22. $tmpl->printPage();
  23. exit;
  24. }
  25. if (OC_Filesystem::is_dir($source)) {
  26. $files = array();
  27. $rootLength = strlen($root);
  28. foreach (OC_Files::getdirectorycontent($source) as $i) {
  29. $i['date'] = OC_Util::formatDate($i['mtime'] );
  30. if ($i['type'] == 'file') {
  31. $fileinfo = pathinfo($i['name']);
  32. $i['basename'] = $fileinfo['filename'];
  33. $i['extention'] = isset($fileinfo['extension']) ? ('.'.$fileinfo['extension']) : '';
  34. }
  35. $i['directory'] = substr($i['directory'], $rootLength);
  36. if ($i['directory'] == "/") {
  37. $i['directory'] = "";
  38. }
  39. $files[] = $i;
  40. }
  41. // Make breadcrumb
  42. $breadcrumb = array();
  43. $pathtohere = "";
  44. foreach (explode("/", $subPath) as $i) {
  45. if ($i != "") {
  46. $pathtohere .= "/$i";
  47. $breadcrumb[] = array("dir" => $pathtohere, "name" => $i);
  48. }
  49. }
  50. // Load the files we need
  51. OC_Util::addStyle("files", "files");
  52. $breadcrumbNav = new OC_Template("files", "part.breadcrumb", "");
  53. $breadcrumbNav->assign("breadcrumb", $breadcrumb);
  54. $breadcrumbNav->assign("baseURL", OC_Helper::linkTo("files_sharing", "get.php")."?token=".$token."&path=");
  55. $list = new OC_Template("files", "part.list", "");
  56. $list->assign("files", $files);
  57. $list->assign("baseURL", OC_Helper::linkTo("files_sharing", "get.php")."?token=".$token."&path=");
  58. $list->assign("downloadURL", OC_Helper::linkTo("files_sharing", "get.php")."?token=".$token."&path=");
  59. $list->assign("readonly", true);
  60. $tmpl = new OC_Template("files", "index", "user");
  61. $tmpl->assign("fileList", $list->fetchPage());
  62. $tmpl->assign("breadcrumb", $breadcrumbNav->fetchPage());
  63. $tmpl->assign("readonly", true);
  64. $tmpl->printPage();
  65. } else {
  66. //get time mimetype and set the headers
  67. $mimetype = OC_Filesystem::getMimeType($source);
  68. header("Content-Transfer-Encoding: binary");
  69. header("Expires: 0");
  70. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  71. header("Pragma: public");
  72. header('Content-Disposition: filename="'.basename($source).'"');
  73. header("Content-Type: " . $mimetype);
  74. header("Content-Length: " . OC_Filesystem::filesize($source));
  75. //download the file
  76. @ob_clean();
  77. OC_Filesystem::readfile($source);
  78. }
  79. } else {
  80. header("HTTP/1.0 404 Not Found");
  81. $tmpl = new OC_Template("", "404", "guest");
  82. $tmpl->printPage();
  83. die();
  84. }
  85. ?>