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 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误