Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <video controls preload="auto" id="video1">
- <% if $VideoMP4 %><source src="id/$Video($VideoMP4.ID)" type="video/mp4"><% end_if %>
- Your browser does not support HTML5 video.
- </video>
- class PageVideo extends Page {
- private static $has_one = array(
- 'VideoMP4' => 'File',
- );
- function getCMSFields() {
- $fields = parent::getCMSFields();
- $fields->addFieldToTab(
- 'Root.Main ',
- $uploadField = new ChunkedUploadField(
- $name = 'VideoMP4',
- $title = "VideoMP4"
- )
- );
- $uploadField->setFolderName('Uploads/videos/');
- $uploadField->setDisplayFolderName('Uploads/videos');
- $uploadField->getValidator()->allowedExtensions = array("mp4");
- $sizeMB = 500 * 1024 * 1024; // 500 MB in bytes
- $uploadField->getValidator()->setAllowedMaxFileSize($sizeMB);
- $uploadField->setConfig('maxChunkSize', .05 * 1024 * 1024 );
- return $fields;
- }
- }
- class PageVideo_Controller extends Page_Controller {
- private static $allowed_actions = array('VideoGrab');
- private static $url_handlers = array('id/$hash' => 'VideoGrab');
- public function VideoGrab(SS_HTTPRequest $request) {
- $hash = $request->param('hash');
- $file = File::get()->filter('ID', $_SESSION['keyID'])->first();
- if (md5($file->Name.$_SESSION['key'])==$hash) {
- $_SESSION['key']="";
- $_SESSION['keyID']="";
- //**************** HERE IS THE CLASS *********************
- include "libraries/VideoStream.php";
- $stream = new VideoStream($file->AbsoluteURL);
- $stream->start(); exit;
- // the original php working just for some browsing and bad codes
- /*
- $ext = pathinfo($file->Filename);
- header('Cache-control: private');
- header('Content-Type: video/'.$ext['extension']);
- header('Accept-Ranges: bytes');
- header("Content-Transfer-Encoding: binary");
- return readfile($file->AbsoluteURL); exit;
- */
- } else {
- return $this->httpError(404, "Not Found");
- }
- }
- public function Video($n) {
- $file = File::get()->filter('ID', $n)->First();
- $_SESSION['key']=time();
- $_SESSION['keyID']=$file->ID;
- return md5($file->Name.$_SESSION['key']);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement