Php Video Upload Script

2019-02-11 11:39发布

问题:

I am trying to allow users to upload videos via this form

       <form method='POST' name='uploadform' enctype='multipart/form-data' action=''>
                                Video: <input type='file' name='filename' /><br/>
                                       <input type='submit' name='cmdSubmit' value='Upload' />";

Then with this php script I am trying to move the videos into another folder for storage.

            if($_POST['cmdSubmit']){
                            $filename = basename($_FILES['filename']['name']);
                            move_uploaded_file($_FILES['filename']['tmp_name'], "videos/" . $filename);
                    }

The problem I am having is the video's are not being moved to my folder. I have done research on how to do this and have try many error solving methods but nothing is seeming to work so if you have any idea on what my problem is any help is appreciated. The form works perfectly. Thanks....

I have searched google and youtube and can't find any really good articles on this if you know any that would be awesome too.

I tried to do troubleshooting by using this code..

if(move_uploaded_file($_FILES['filename']['tmp_name'], "videos/" . $filename)){
                                echo "This worked Successfully";

                            }else{
                                echo "Error";   
                            }
                    }

and it did not echo either statement....

回答1:

Try the below PHP code in this code you can have some Restrictions on Upload you can set the Exts that you need to allow in upload..

HTML FORM CODE

<html>
<body>
<form action="upload_file.php" method="post"   enctype="multipart/form-data">
  <label for="file">Filename:</label>
     <input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html> 

PHP CODE BELOW

<?php
$allowedExts = array("jpg", "jpeg", "gif", "png");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000)
&& 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";
  }
?> 

For Any Other Reference kindly Check Here http://w3schools.com/php/php_file_upload.asp Or Post A Comment



回答2:

In php.ini Find and update as following:

post_max_size = 8M

upload_max_filesize = 2M

max_execution_time = 30

max_input_time = 60

memory_limit = 8M

Change to:

post_max_size = 750M

upload_max_filesize = 750M

max_execution_time = 5000

max_input_time = 5000

memory_limit = 1000M