doz97171 2016-02-04 12:28
浏览 95

如何使用JavaScript和PHP制作网络摄像头流?

I want to create a webcam stream, how I start my webcam on the admin page and insert a widget into the FrontEnd which is load the stream which is streamed from the admin site.

I solved how view the webcam on the admin page and how to load a video on the FrontEnd.

So how can I send the webcamera image continously and save it on the server temporarly, how only the last few seconds of the video is stored ( this last one is not important ) and load it on the FrontEnd?

  • 写回答

1条回答 默认 最新

  • Rocky44 2020-07-14 09:50
    关注

    如果你可以看到这篇英文文章
    的话,也许会对你有一定的帮助。你可以借助文中提到的工具进行图像上传到服务器的操作,并随时下载。

    JavaScript 部分用的是 webcam SDK

    PHP代码

    创建一个操作页面upload.php以从Web客户端接收图像:

    <?php
        $strJson = "{\"success\":false}";
    
        try{
    
            $file = $_FILES["RemoteFile"];
    
            $fileName = $_POST["fileName"];
            if ($fileName == "" || $fileName == null) $fileName = $file["name"];
    
            $filePath = dirname(__FILE__) . "/upload/";
            if (!file_exists($filePath)) {
                mkdir($filePath);
            }
    
            if (file_exists($filePath . $fileName))
            {
                $iniNum = 0;
                if (strpos($fileName, "(") !== FALSE && strpos($fileName, ")") !== FALSE)
                {
                    $leftPhPos =  strrpos($fileName, "(");
                    $rightPhPos = strrpos($fileName, ")");
                    if ($leftPhPos < $rightPhPos) {
                        $numStr = substr($fileName, $leftPhPos + 1, $rightPhPos - $leftPhPos - 1);
                        if (is_numeric($numStr))
                        {
                            $iniNum = intval($numStr);
                            $fileName = substr($fileName, 0, $leftPhPos) . substr($fileName, $rightPhPos + 1);
                        }
                        else { 
                            $iniNum = 0;
                        }
                    }
                }
                $indexPoint = strrpos($fileName, ".");
                $str1 = substr($fileName, 0, $indexPoint) . "(";
                $str2 = ")" . substr($fileName, $indexPoint);
                for ($i = $iniNum; ; ++$i)
                {
                    if (!file_exists($filePath . ($str1 . $i . $str2)))
                    {
                        $fileName = $str1 . $i . $str2;
                        break;
                    }
                }
            }
    
            $fileFullPath = $filePath . $fileName;
    
            if(strpos($file["type"], 'text/plain') === false){
                move_uploaded_file($file["tmp_name"] , $fileFullPath);
            }else{
                $file_contents = base64_decode(str_replace(' ', '+', file_get_contents($file['tmp_name'])));
                file_put_contents($fileFullPath, $file_contents);
            }
    
            $strJson = "{\"success\":true, \"fileName\":\"" . $fileName . "\"}";
    
    
        }
        catch(Exception $ex){
            $strJson = "{\"success\":false, \"error\": \"" . ex.Message.Replace("\\", "\\\\") . "\"}";
        }   
    
        // Response.Clear();
        header("Content-Type: application/json; charset=utf-8");
        echo $strJson;
    ?>
    
    
    评论

报告相同问题?

悬赏问题

  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上