简体   繁体   中英

Temporary video streaming URL

I am trying to create an url to provide a video only one time. I will use that as an src for the video tag.

The idea is. Create an temporary and valid url. When the page is open I check if the page is valid (there is a temporary table with valid registers), get the data, delete the temporary register and open the file.

The problem is, if i delete the temporary register, after I get the data, the video streaming does not works.

It seems that it does not acts like a file descriptor, when, after it is open, even if i delete the node it keeps open.

The code that i am using is:

    $temp=Temporaryvideo::model()->findByAttributes(array("video_id" => "$content", "hash" => "$key"));

    if(count($temp)==1){

        $video=Video::model()->findByPk($content);
        $filename=$video->attributes['video_url'];

        header('Pragma: public');
        header('Expires: -1');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Cache-Control: private', false); // required for certain browsers ); 
        header('Content-Type: video/mp4');

        header('Content-Length: ' . filesize("videos/$filename"));
        //$temp->delete();
        readfile("videos/$filename");
    }

That works fine until i delete the register from the database. Is there a way to make the url valid only once? I want to do that to avoid people from downloading the video. I know that there is other ways for them to get the video, but that will avoid some people to do that.

Changing the content-type to application/octet-stream solves that issue, but i cannot go forward or to the begin of the video.

In the end the best solution was to use

$temp=Temporaryvideo::model()->findByAttributes(array("video_id" => "$content", "hash" => "$key"));

if(count($temp)==1){

    $video=Video::model()->findByPk($content);
    $filename=$video->attributes['video_url'];

    header('Pragma: public');
    header('Expires: -1');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Cache-Control: private', false); // required for certain browsers ); 
    header('Content-Type: application/octet-stream');

    header('Content-Length: ' . filesize("videos/$filename"));
    $temp->delete();
    readfile("videos/$filename");
}

That way the url is invalidate and the streaming continues. If you try to go forward or backward on the video, it will break.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM