我有一个PHP / JS文件上传,我希望在100%上传前播放视频。
我是如何做到的?
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>
答案 0 :(得分:0)
好的,所以你想在上传视频之前向人们展示他们所选择的内容。
HTML&amp; JavaScript代码
(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)
})()
&#13;
<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>
&#13;
只需使用此代码就可以了。