douhui3330 2017-08-23 10:21
浏览 67
已采纳

PHP流来自临时路径的文件?

I have a PHP/JS fileupload and I want to stream a video before it is 100% uploaded.

How I make that?

fileupload.html (JS, uploadFile()):

var file = document.getElementById("file1").files[0];   
var formdata = new FormData();
formdata.append("file1", file);
var ajax = new XMLHttpRequest();
ajax.upload.addEventListener("progress", progressHandler, false);
ajax.open("POST", "file_upload_parser.php");
ajax.send(formdata);

fileupload.html (html)

<form id="upload_form" enctype="multipart/form-data" method="post">
  <input class="fileUpload" type="file" name="file1" id="file1"><br>
  <input id="uploadBtn" type="button" value="Upload File" onclick="uploadFile()">
</form>

file_upload_parser.php:

<?php
$fileName = $_FILES["file1"]["name"];
$fileTmpLoc = $_FILES["file1"]["tmp_name"];

if(move_uploaded_file($fileTmpLoc, "uploads/$fileName")){
    echo "complete";
}
?>

VideoStream.php: https://gist.github.com/ranacseruet/9826293

streamer.php

<?php
    $path = $_GET['path'];
    include "VideoStream.php";
    $stream = new VideoStream($path); 
    $stream->start();exit;
?>

<video controls preload="auto" src="<?php echo $path ?>" width="100%"></video>
  • 写回答

1条回答 默认 最新

  • duanrou5680 2017-08-23 10:30
    关注

    Alright, so you want to show people a preview of what they choose before they upload the video.

    HTML & JavaScript Code

    (function Preview_Video() {
        'use strict'
      var URL = window.URL || window.webkitURL
     
     
      var Play_Video = function (event) {
        var file = this.files[0]
        var type = file.type
        var videoNode = document.querySelector('video')
        var fileURL = URL.createObjectURL(file)
        videoNode.src = fileURL
      }
      
      var inputNode = document.querySelector('input')
      inputNode.addEventListener('change', Play_Video, false)
    })()
    <div id="video"></div>
    <video controls autoplay></video>
    
    <form method="POST" name="form">
    <input type="file" name="media-vid" accept="video/*"/>
    <input type="submit" name="submit" value="submit"/>
    </form>

    Just use this code and you will be good.

    Example picture from my website/screen:
    enter image description here

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用