你好,我有以下代碼:的Javascript獲取視頻長度
<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>
這裏是我的一些PHP代碼它被張貼後:
if(FileSize($_FILES["video"]["tmp_name"]) >= 120){
$uploadable = false;
header("Location:post-video");
$_SESSION["FLAW"] = '10';
}
我想要的瀏覽器訪問錯誤如果發佈的視頻的文件大小大於120個字節(例如),則稱爲後視頻。我現在遇到的問題是它會發布整個視頻,如果用戶上傳一個非常大的視頻文件,可能需要10分鐘。視頻發佈後,它大於120bytes,顯示錯誤屏幕。有沒有辦法,可能使用JavaScript來儘早檢測視頻的大小?如果是這樣,我該如何快速做到這一點?
你可以添加一些JavaScript來檢查這個: 'var file = d 。ocument.getElementById( 「videoage」)文件[0]; if(file.size> 120) {/ *做些什麼* /}' – vbguyny
@vbguyny感謝它的工作回答,所以你可以得到信用 – user7133318
謝謝。您應該能夠將我的評論標記爲答案。 – vbguyny