Javascript获取视频长度
您好,我有以下代码:Javascript获取视频长度,javascript,php,Javascript,Php,您好,我有以下代码: <form action="postvideophp.php" method="post" enctype="multipart/form-data"> <input id="videoage" type="file" name="video" style="-webkit-appearance: none;-webkit-border-radius: 0;margin-left:-242px;margi
<form action="postvideophp.php" method="post" enctype="multipart/form-data">
<input id="videoage" type="file" name="video" style="-webkit-appearance: none;-webkit-border-radius: 0;margin-left:-242px;margin-top:10px;opacity:0;">
<label for="videoage" id="labelvideo">Choose Video...</label>
<textarea id="postTitleStyle" onkeyup="countChars('postTitleStyle','titlecount');" onkeydown="countChars('postTitleStyle','titlecount');" onmouseout="countChars('postTitleStyle','titlecount');" name="title" rows="1" maxlength = "180" placeholder="Title"><?php echo $title;?></textarea>
<a id="titlecount" style="color:#F52025;Font-family:Arial Black;display:table;margin-top:-20px;margin-left:840px;">0</a>
<textarea id="postTagStyle" onkeyup="countChars2('postTagStyle','descripcount');" onkeydown="countChars2('postTagStyle','descripcount');" onmouseout="countChars2('postTagStyle','descripcount');" name="desc" rows="2" maxlength = "1000" placeholder="Description"><?php echo $DESC;?></textarea>
<a id="descripcount" style="color:#3FDA21;Font-family:Arial Black;display:table;margin-top:-20px;margin-left:840px;">0</a>
<center><input type="submit" class = "Post2" value="[ Post ]"></center>
</form>
如果发布的视频文件大小大于120字节(例如),我希望浏览器转到名为“发布视频”的错误屏幕。我现在遇到的问题是,如果用户上传一个非常大的视频文件,它会发布整个视频,这可能需要10分钟。视频上传后,超过120字节,错误屏幕显示。有没有一种方法可以在早期使用javascript检测视频的大小?如果是这样的话,我如何才能快速完成此操作?您可以通过
$\u FILES
超级全局文件获取文件大小
if ($_FILES["video"]['size'] >= $fileLimit) {
// handle oversized file
}
您可以使用此客户端在受支持的浏览器中更快地处理错误,方法是:
var fileInput = document.getElementById("videoage");
fileInput.addEventListener("change", function () {
if (fileInput.files[0].size > 120) {
alert("file too big");
}
});
您可以添加一些JavaScript来检查这一点:
var file = document.getElementById("videoage").files[0];
if (file.size > 120) { /* do something */ }
您可以添加一些JavaScript来检查这一点:
var file=document.getElementById(“videoage”).files[0];如果(file.size>120){/*做点什么*/}
@vbguyny谢谢它工作了,那么你就可以得到信用了谢谢。你应该可以把我的评论标记为答案。@vbguyny我没有这个选择。Stackoverflow最近一定改变了这一点……这是PHP,而不是javascriptUpdated来添加javascript解决方案
var file = document.getElementById("videoage").files[0];
if (file.size > 120) { /* do something */ }