Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Php video validation.

Guest
Jun 22, 2011 Jun 22, 2011

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";

}

TOPICS
Server side applications
3.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jul 02, 2011 Jul 02, 2011

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

...
Translate
Guest
Jun 22, 2011 Jun 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 22, 2011 Jun 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 22, 2011 Jun 22, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 23, 2011 Jun 23, 2011

Hi this is the code:

if($_POST['submit'])
{



        $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 (($_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"))
  {
  if ($_FILES["filename"]["error"] > 0)
    {
    echo "Error: " . $_FILES["filename"]["error"] . "<br />";
    }
  else
    {
      if($_FILE["filename"]["size"]<74295516)
      {

    //Video conversion  and database insert happens here.


      }
      else
      {
          echo "<font color='#8B2323' size='3' face='Times New Roman, Times, serif'>Only less than five minute videos allowed.</font>";
      }
    }
  }
else
  {

//I get this error even when the file video type is accepted.
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>";
}
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 23, 2011 Jun 23, 2011

Tony

I would add this to line one and see what you get

error_reporting(E_ALL);

This turns on error reporiting.

Second, you have

if($_POST['submit'])

if()  is asking to check if  a condition exists, yours does not.  Try changing to

if(isset($_POST['submit']))

Check to make sure if you are using the if() in other places that there is a condition to be met.

It would also seem you are using single and double quotes in a way I have not seen before.

$type=$_FILES["filename"]["type"];

Typically single quotes are used, frankly I dont know if that will throw you off, but try to get consistant with your code writing. The error reporting might give you a clue.

Last, the reason I asked for you to post a link is so people can see how your form is written, you did not, so we can't compare the form with the form processing script, which just handicaps your getting your issue solved.

Gary

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 30, 2011 Jun 30, 2011

Hi Thanks for reply.

I do not think its the quotes I tried it without double quotes. I have done image validation before but this is my first video validation. Any way I have

uploaded all the actually code:

The error is related to the video type check which says incorrect video type even when the video type is correct thanks.

if(isset($_POST['submit']))
{
    //Session
        $id=$_SESSION['id'];
        $expid=$_GET['expid'];


        $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 (($_FILES["filename"]["type"] == "video/flv")
|| ($_FILES["filename"]["type"] == "video/avi")
|| ($_FILES["filename"]["type"] == "video/mov")
|| ($_FILES["filename"]["type"] == "video/wmv"))
  {
  if ($_FILES["filename"]["error"] > 0)
    {
    echo "Error: " . $_FILES["filename"]["error"] . "<br />";
    }
  else
    {
      if($_FILE["filename"]["size"]<74295516)
      {

          //Video upload happens hear.
      }
      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>";
}
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 30, 2011 Jun 30, 2011

What do you expect the following argument to do for you?

if($title&&$filename&&$desc&&$tags) {

// other stuff here

} else {
echo "<font color='#8B2323' size='3' face='Times New Roman, Times, serif'>Only less than five minute videos allowed.</font>";
}

The error message is displayed because the condition if($title&&$filename&&$desc&&$tags) does not return a true value.

This would of been determined a week ago when you first started the thread had you provided the code in your original post. Tip: when you're asking about code it's a good idea to provide it so that others can diagnose. Saying "my car won't start" doesn't help until you open the hood.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 30, 2011 Jun 30, 2011

Hi

Please re check the code not forgetting the if statement at the top.

echo "<font color='#8B2323' size='3' face='Times New Roman, Times, serif'>Upload must be an video wmv, mov, avi or flv.</font>";

is the actual error I get. When I remove the video type if statement the upload works but I need the video type check to make sure

millisous code is not uploaded.

echo "<font color='#8B2323' size='3' face='Times New Roman, Times, serif'>Only less than five minute videos allowed.</font>";

Is actually connected to the file size check that happens before the video upload part.

Thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 30, 2011 Jun 30, 2011
When I remove the video type if statement the upload works

Provide code that works for comparison. There was a typo in the error message I displayed in the previous message but the problem remains that your if statement for $this&&$that&&$somethingelse does not return a true value. There isn't an argument to determine a value of the condition. You're basically saying if... but not saying WHAT of the if. Make sense? Like what was described earlier where if POST value isset you would need to say if $this = something or not null or something to determine a true value of the argument. Again, your current argument simply says if... without specifying WHAT condition of the if statement must be met.

What file are you trying to upload for the test? provide metadata for the file you are using to test the function.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 02, 2011 Jul 02, 2011

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>";
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 02, 2011 Jul 02, 2011

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

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 02, 2011 Jul 02, 2011

Hi David

You are absolutely right I echoed type and got  video/x-msvideo on my netscape browse when the actual video is .avi.

I then went to internet explorer and got the echoed video as avi.

I am not sure why this happens but I will add x-msvideo to thelist and use the array you adviced. Thank you so much.

One more thing do you know a web link that provides all the different formats based on browser information etc.

Thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 03, 2011 Jul 03, 2011
LATEST

Tony404 wrote:

One more thing do you know a web link that provides all the different formats based on browser information etc.

The different values aren't identified by browser, but this list is fairly exhaustive: http://www.webmaster-toolkit.com/mime-types.shtml.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines