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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?