doude5860 2016-03-22 01:02
浏览 121

临时视频流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.

  • 写回答

1条回答 默认 最新

  • dongshen9686 2016-03-22 15:35
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算