I am trying to allow my users to upload videos to my site and i have the php file upload but it will not work, it worked with images but once i changed it to video it stopped working this is the code

<?php
$allowedExts = array("mp4", "mov", "avi", "flv","mpg", "wmv", "3gp", "rm");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "video/mov")
|| ($_FILES["file"]["type"] == "video/avi")
|| ($_FILES["file"]["type"] == "video/flv")
|| ($_FILES["file"]["type"] == "video/mpg")
|| ($_FILES["file"]["type"] == "video/wmv")
|| ($_FILES["file"]["type"] == "video/3gp")
|| ($_FILES["file"]["type"] == "video/rm"))
&& in_array($extension, $allowedExts))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }
?>

Quick guess: If the code works for images you maybe having a timeout problem due to the size of the videofiles, OR the filesize is larger than the allowed filesize.

Check the errorcode from $_FILES["file"]["error"]. The value 1 means the file is larger than the allowed filesize (from php.ini).

Greetings
Steen Andersen

I am in the same problem. please help anyone....

increase your allowed filesize from php.ini file and then check may be it is 8MB by default

Like dpste123 said:

Check the errorcode from $_FILES["file"]["error"]. The value 1 means the file is larger than the allowed filesize (from php.ini).

It's likely that this is a file size issue, in which case changing the config will help, but there are also other issues that could be affecting you. The $_FILES["file"]["error"] value will tell us exactly what the problem is, so we don't have to waste time guessing. You can compare the error code you get with the list in the manual.

Try these,,

if ((($_FILES["file"]["type"] == "video/mov")
    || ($_FILES["file"]["type"] == "video/avi")
    || ($_FILES["file"]["type"] == "video/x-msvideo")
    || ($_FILES["file"]["type"] == "video/flv")
    || ($_FILES["file"]["type"] == "video/x-flv")
    || ($_FILES["file"]["type"] == "video/mpg")
    || ($_FILES["file"]["type"] == "video/wmv")
    || ($_FILES["file"]["type"] == "video/3gp")
    || ($_FILES["file"]["type"] == "video/3gpp")
    || ($_FILES["file"]["type"] == "video/rm"))


|| ($_FILES["file"]["type"] == "video/x-msvideo")
|| ($_FILES["file"]["type"] == "video/flv")
|| ($_FILES["file"]["type"] == "video/x-flv")
|| ($_FILES["file"]["type"] == "video/mpg")
|| ($_FILES["file"]["type"] == "video/wmv")
|| ($_FILES["file"]["type"] == "video/3gp")
|| ($_FILES["file"]["type"] == "video/3gpp")
|| ($_FILES["file"]["type"] == "video/rm"))
Member Avatar for diafol

Any reason we're resurrecting a 3 year old thread? Anyhow very cumbersome. An array to store types would be easier IMO:

$vArray = ["video/mov", "video/avi", "video/x-msvideo", ...];
if(in_array($_FILES["file"]["type"], $vArray){
    //found
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.