PHP视频上传脚本 [英] Php Video Upload Script

查看:209
本文介绍了PHP视频上传脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让用户通过这个表格上传视频

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

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

  if $ _POST ['cmdSubmit']){
$ filename = basename($ _ FILES ['filename'] ['name']);
move_uploaded_file($ _ FILES ['filename'] ['tmp_name'] ,videos /。$ filename);
}

视频没有被移动到我的文件夹我已经做了研究如何做到这一点,并尝试了很多错误的解决方法,但没有什么是似乎工作,所以如果你有什么我的问题是任何帮助表示赞赏。完美的作品。谢谢....

我已经搜索谷歌和youtube,并找不到任何真正好的文章,如果你知道任何也是很棒的。



我尝试使用此代码进行故障排除。

  if(move_uploaded_file($ _ FILES ['filename'] ['tmp_name'],videos /)。 $ filename)){
echoThis Successful Successfully;

} else {
echoError;


code
$ b

你可以在上传
上设置一些限制,你可以设置你在上传时需要允许的Exts。




HTML FORM < HTML>
< body>
< form action =upload_file.phpmethod =postenctype =multipart / form-data>
< label for =file>文件名:< / label>
< input type =filename =fileid =file/>
< br />
< input type =submitname =submitvalue =Submit/>
< / form>
< / body>
< / html>

PHP 以下代码

 <?php 
$ allowedExts = array(jpg,jpeg,gif,png);
$ extension = end(explode(。,$ _FILES [file] [name]));
if((($ _FILES [file] [type] ==image / gif)
||($ _FILES [file] [type] ==图片/ jpeg)
||($ _FILES [file] [type] ==image / pjpeg))
&&($ _FILES [file] [ ($ _FILES [file] [error]>);
& amp; in_array($ extension,$ allowedExts))
{
if 0)
{
echo返回代码:。 $ _FILES [file] [error]。 < br />;
}
else
{
echoUpload:。 $ _FILES [file] [name]。 < br />;
回显类型:。 $ _FILES [file] [type]。 < br />;
回声大小:。 ($ _FILES [file] [size] / 1024)。 Kb< br />;
回显临时文件:。 $ _FILES [file] [tmp_name]。 < br />;
$ b $ if(file_exists(upload /。$ _FILES [file] [name]))
{
echo $ _FILES [file] [名称] 。 已经存在。 ;


$ $ b $ move_uploaded_file($ _ FILES [file] [tmp_name],
upload /。$ _FILES [file] [名称]);
回声存储在:。 上传/。 $ _FILES [ 文件] [ 名称];





echoInvalid file;
}
?>

任何其他参考 code> http://w3schools.com/php/php_file_upload.asp 或发表评论

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

解决方案

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

这篇关于PHP视频上传脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆