Skip to main content
June 22, 2011
Answered

Php video validation.

  • June 22, 2011
  • 1 reply
  • 3543 views

Hi

I have been trying to validate video types and for some reason the code below always echo File format unexcepted even when the

file is the right format. What could be going wrong thanks.

if (($_FILES["filename"]["type"] == "video/mpeg")
|| ($_FILES["filename"]["type"] == "video/mpeg4")
|| ($_FILES["filename"]["type"] == "video/avi")
|| ($_FILES["filename"]["type"] == "video/mov")
|| ($_FILES["filename"]["type"] == "video/avi")
|| ($_FILES["filename"]["type"] == "video/mpg")
|| ($_FILES["filename"]["type"] == "video/wmv")
|| ($_FILES["filename"]["type"] == "video/vid"))

{

}

else

{

echo "File format  un excepted";

}

This topic has been closed for replies.
Correct answer David_Powers

Hi Again

The uploaded code here works and if you notice I have editted out the video type section. If the video type is not editted out it does not work

saying the video type not accepted even when the video type is correct.

        $title=addslashes(strip_tags($_POST['title']));
        $desc=addslashes(strip_tags($_POST['desc']));
        $tags=addslashes(strip_tags($_POST['tags']));


    $filename = basename($_FILES['filename']['name']);
        $type=$_FILES["filename"]["type"];
        $size=$_FILES["filename"]["size"];
        $temp_name=$_FILES["filename"]["tmp_name"];
        $error=$_FILES["filename"]["error"];


if($title&&$filename&&$desc&&$tags)
{
/*
if (($type == "video/flv")
|| ($type == "video/avi")
|| ($type == "video/mov")
|| ($type == "video/wmv"))
  { */
  if ($_FILES["filename"]["error"] > 0)
    {
    echo "Error: " . $_FILES["filename"]["error"] . "<br />";
    }
  else
    {
      if($_FILE["filename"]["size"]<74295516)
      {

        echo "Uploading please wait.";

                        
      }
      else
      {
          echo "<font color='#8B2323' size='3' face='Times New Roman, Times, serif'>Only less than five minute videos allowed.</font>";
      }
    }
/*}
else
  {
echo "<font color='#8B2323' size='3' face='Times New Roman, Times, serif'>Upload must be an video wmv, mov, avi or flv.</font>";
  } */

}
else
{
echo "<font color='#8B2323' size='3' face='Times New Roman, Times, serif'>Fill in all fields and make sure you have selected video.</font>";
}


Tony404 wrote:

The uploaded code here works and if you notice I have editted out the video type section. If the video type is not editted out it does not work

saying the video type not accepted even when the video type is correct.

I've not read every single word of this thread, so forgive me if this is something that has already been covered. Have you tried using echo to see what $type contains?

I'm pretty certain that PHP doesn't test the MIME type itself. It just accepts the value submitted by the browser. In the case of JPEG files, Internet Explorer uses image/pjpeg instead of the standard image/jpeg. It's possible that the MIME type is being submitted in a different format from those that you're testing for. You might also find it more convenient to create an array of MIME types and use in_array() rather than a series of comparison operators. For example:

$mimetypes = array('video/mov', 'video/flv', 'video/avi');

if (in_array($type, $mimetypes)) {

  // it's OK

}

1 reply

June 22, 2011

Without more info it's hard to tell. My speculation is that the file filed to upload the file in your form is not named filename as indicated in your provided code.

June 22, 2011

Hi

I can garantee the file name is filename. Its my first time doing video validation but the filename is definetely filename.


<input type="file" name="filename" />

Thanks.

June 23, 2011

Tony

If you want someone to look at your code to tell you what is going wrong, dont you think you should just post the code? A link might help in addition to the complete php...

Gary