user7133318 user7133318 - 4 months ago 27
Javascript Question

Javascript Get video length

Hello I have the following code:

<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="[&nbsp;&nbsp;Post&nbsp;&nbsp;]"></center>

And here is some of my php code after it gets posted:

if(FileSize($_FILES["video"]["tmp_name"]) >= 120){
$uploadable = false;
$_SESSION["FLAW"] = '10';


I want the browser to go to an error screen called post-video when if the filesize of the posted video is greater than 120 bytes(for example). The problem I currently have is that it posts the whole video which could take 10 minutes if the user uploads a really big video file. After the video is posted and it is bigger than 120bytes the error screen displays. Is there a way, possible using javascript to detect the size of the video early on? If so how can i do this quickly?


You can add some JavaScript to check for this:

 var file = document.getElementById("videoage").files[0]; 
if (file.size > 120) { /* do something */ }