php PHP视频上传脚本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11839127/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 02:14:59  来源:igfitidea点击:

Php Video Upload Script

phphtmlformsfile-uploaddirectory

提问by Keith Drake Waggoner

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.

然后使用这个 php 脚本,我试图将视频移动到另一个文件夹中进行存储。

            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.

我在谷歌和 YouTube 上搜索过,如果你知道任何很棒的文章,也找不到任何关于这方面的真正好的文章。

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....

它没有回应任何声明......

回答by Varun Sridharan

Try the below PHPcode in this code you can have some Restrictionson Upload you can set the Exts that you need to allow in upload..

PHP在此代码中尝试以下代码,您可以Restrictions在上传中使用一些代码,您可以设置您需要在上传中允许的分机..

HTMLFORMCODE

HTMLFORM代码

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

PHPCODE BELOW

PHP代码如下

<?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 Referencekindly Check Here http://w3schools.com/php/php_file_upload.aspOr Post A Comment

对于任何其他人,Reference请在此处查看http://w3schools.com/php/php_file_upload.asp或发表评论

回答by user2878581

In php.ini Find and update as following:

在 php.ini 中查找并更新如下:

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