doubu8643 2017-06-26 01:46 采纳率: 100%
浏览 288
已采纳

如何从服务器上传和播放不同格式的视频?

I'm using a goDaddy server and cPanel to make a website, and I want to make a feature that lets users upload videos, save them on the server, then display them elsewhere on the site.

echo "<iframe src='uploads/videos/sample.mov' frameborder='0' allowfullscreen></iframe>";

How can i get video formats like .mov to play on the site after they are uploaded on the server?

We’re currently able to get mp4 to work with the below code, but I don’t want to limit users to only upload mp4

if(isset($_FILES["submit_file"])){ //this comes from an html form
$name = $_FILES['submit_file']['name'];
$original_name = $name;
$size = $_FILES['submit_file']['size'];
$tmp_name = $_FILES['submit_file']['tmp_name'];
$target_dir = null;

$finfo = finfo_open(FILEINFO_MIME_TYPE);//get mime type
$mime = finfo_file($finfo, $tmp_name);

if ($mime == "video/mp4" || $mime == "video/wmv" || $mime == "video/avi" || $mime == "video/mov")
{
    $target_dir = "uploads/videos/";
    $path = $target_dir . basename($name);

    if (move_uploaded_file($tmp_name, $path) == true) {
        //moved
    }
}else{
    //error: Unsupported File Type;
}
}

How do sites like facebook allow uploading videos other than mp4? I looked into using FFmpeg to convert everything to mp4, but I don't see how to install and use that on the godaddy server.

  • 写回答

1条回答 默认 最新

  • dongzhen4180 2017-06-26 02:04
    关注

    Effectively, sites like Facebook doesn't just store the video in their filesystems but convert them using FFmpeg or similar library. You won't be able to install it unless you're running a VPS or Dedicated Server. If you are running a Shared hosting the service provider could install it for you but in my experience they won't because you will consume the resources of the people sharing the instance with you (seems legit :) )

    About the code, it's is just checking the file mime type prior to save it to your storage and as far as I can see it should accept other formats like avi, wmv and mov.

    Take in count that that code won't check that the file is effectively a video file, it'll just check the extension (the file could have encoding errors and you wouldn't know).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题