How to upload video in php?

Asked By 0 points N/A Posted on -
qa-featured

 

Hi techyv,

How to upload video in php? I want a code that can probably lead me on how to let the user of the website upload a video and photo. I need to make this online survey to get different opinion from those experts here in techyv. I am not that familiar with this php programming language that is why I need some help.

Hoping for your help. Thanks.

SHARE
Answered By 0 points N/A #182127

How to upload video in php?

qa-featured

Hi:

this is the php:

 

<?php
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}

$connect = mysql_connect('localhost','root','');
  mysql_select_db('database',$connect);
mysql_query("INSERT INTO movie(name, size, type, content ) VALUES({$fileName},{$fileSize},{$fileType},{$content})");
die('Error, query failed');
mysql_close($connect);

echo "<br>File $fileName uploaded<br>";
}
?>

and this is the code html:

<form action="upload.php" method="post" enctype="multipart/form-data">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input name="userfile" type="file" id="userfile">
</td>
<td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
</tr>
</table>
</form>

Answered By 0 points N/A #182128

How to upload video in php?

qa-featured

Make one file name " file.php"

Put this HTML code in that.

 

<!DOCTYPE html>



<head>

<title></title>

</head>



<body>



<form action="upload_file.php" method="post" enctype="multipart/form-data">

<label for="file"><span>Filename:</span></label>

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

<br />

<input type="submit" name="submit" value="Submit" />

</form>



</body>

</html>

 

 "upload_file.php"

<?php





if ((($_FILES["file"]["type"] == "video/mp4")

|| ($_FILES["file"]["type"] == "audio/mp3")

|| ($_FILES["file"]["type"] == "video/wmv")

|| ($_FILES["file"]["type"] == "image/pjpeg")

|| ($_FILES["file"]["type"] == "image/gif")

|| ($_FILES["file"]["type"] == "image/jpeg"))



&& ($_FILES["file"]["size"] > 20000))



  {

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

  }



?>

 

 

Login/Register to Answer

Related Questions