Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. <video controls preload="auto" id="video1">
  2. <% if $VideoMP4 %><source src="id/$Video($VideoMP4.ID)" type="video/mp4"><% end_if %>
  3. Your browser does not support HTML5 video.
  4. </video>
  5.  
  6. class PageVideo extends Page {
  7.  
  8. private static $has_one = array(
  9. 'VideoMP4' => 'File',
  10. );
  11.  
  12. function getCMSFields() {
  13. $fields = parent::getCMSFields();
  14.  
  15. $fields->addFieldToTab(
  16. 'Root.Main ',
  17. $uploadField = new ChunkedUploadField(
  18. $name = 'VideoMP4',
  19. $title = "VideoMP4"
  20. )
  21. );
  22.  
  23. $uploadField->setFolderName('Uploads/videos/');
  24. $uploadField->setDisplayFolderName('Uploads/videos');
  25. $uploadField->getValidator()->allowedExtensions = array("mp4");
  26.  
  27. $sizeMB = 500 * 1024 * 1024; // 500 MB in bytes
  28. $uploadField->getValidator()->setAllowedMaxFileSize($sizeMB);
  29. $uploadField->setConfig('maxChunkSize', .05 * 1024 * 1024 );
  30.  
  31. return $fields;
  32.  
  33. }
  34.  
  35. }
  36. class PageVideo_Controller extends Page_Controller {
  37.  
  38. private static $allowed_actions = array('VideoGrab');
  39. private static $url_handlers = array('id/$hash' => 'VideoGrab');
  40.  
  41. public function VideoGrab(SS_HTTPRequest $request) {
  42.  
  43. $hash = $request->param('hash');
  44.  
  45. $file = File::get()->filter('ID', $_SESSION['keyID'])->first();
  46.  
  47. if (md5($file->Name.$_SESSION['key'])==$hash) {
  48.  
  49. $_SESSION['key']="";
  50. $_SESSION['keyID']="";
  51.  
  52. //**************** HERE IS THE CLASS *********************
  53. include "libraries/VideoStream.php";
  54. $stream = new VideoStream($file->AbsoluteURL);
  55. $stream->start(); exit;
  56.  
  57.  
  58. // the original php working just for some browsing and bad codes
  59. /*
  60. $ext = pathinfo($file->Filename);
  61. header('Cache-control: private');
  62. header('Content-Type: video/'.$ext['extension']);
  63. header('Accept-Ranges: bytes');
  64. header("Content-Transfer-Encoding: binary");
  65.  
  66. return readfile($file->AbsoluteURL); exit;
  67. */
  68.  
  69.  
  70. } else {
  71. return $this->httpError(404, "Not Found");
  72. }
  73.  
  74. }
  75.  
  76.  
  77. public function Video($n) {
  78.  
  79. $file = File::get()->filter('ID', $n)->First();
  80. $_SESSION['key']=time();
  81. $_SESSION['keyID']=$file->ID;
  82.  
  83. return md5($file->Name.$_SESSION['key']);
  84.  
  85. }
  86.  
  87.  
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement