【问题标题】:Video upload and display in PHP?用 PHP 上传和显示视频?
【发布时间】:2011-04-30 17:11:12
【问题描述】:

我想将视频上传到服务器,然后使用 PHP 的某些播放器(如 youtube)将其显示在网页上。

我的客户问:“视频不得超过 2 分钟,并且必须采用 Quicktime、WMV、Mp4 或 FLV 格式。”

是否有任何开源脚本可以帮助我上传具有客户要求的视频,然后是播放该视频的开源播放器?

请帮忙!

谢谢

【问题讨论】:

  • PHP 是 HTML 预处理器,而不是视频编辑器。
  • 我知道.. 但是必须有一些插件或其他东西可以帮助在 PHP 中实现它?
  • 没有。在 PHP 中,您只能处理文件上传。剩下的就是完全不同的境界了。例如,播放是 Flash(或其他播放器)。 PHP 不播放视频。 PHP 在服务器端运行。没有人可以在服务器上观看视频。

标签: php video video-streaming


【解决方案1】:

这是我最喜欢的解决方案: http://flowplayer.org/

它可以控制很多视频:它使用 javascript 设置和嵌入式 Flash 视频播放器。

编辑:如果您正在寻找好的上传者,请尝试 http://code.google.com/p/swfupload/

它可以进行多次上传和文件类型检查。

【讨论】:

    【解决方案2】:

    首先,您必须创建指向要播放的视频的链接(我在单独的页面上创建了我的视频[index.html])。然后点击一个链接,它会打开页面(play.php)。我假设 index.html 显示来自数据库的视频链接,然后播放脚本的其余部分由 play.php 处理。 见以下代码:

    index.html

        <!doctype html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Untitled Document</title>
    
    <style type="text/css">
    tr:nth-child(odd) {
        background-color: #f2f2f2
    }
    </style>
    </head>
    
    <body>
    <center>
    <table width="53%" border="1">
      <tr>
        <td width="8%">S/NO</td>
        <td width="92%">NAME OF VIDEO FILE</td>
      </tr>
      <tr>
        <td align="center">1</td>
        <td><a href="play.php?url=Funny_Naija_Video_Animation.mp4&pic=ng.png">Funny Nigeria Video Animation</a></td>
      </tr>
      <tr>
        <td align="center">2</td>
        <td><a href="play.php?url=WildGeese.mp4&pic=wg.png">Joan Armatrading- 
      Flight of the Wild Geese - MP4</a></td>
      </tr>
    </table>
    </center>
    </body>
    </html>
    

    play.php

    <!DOCTYPE html>
    <html>
    
    <head>
      <meta charset=utf-8>
      <title>Fluid Width Video</title>
    
      <style>
        * { margin: 0; padding: 0; }
        body { 
          font: 16px/1.4 Georgia, Serif;
          width: 50%; 
          margin: 80px auto; 
          background: url(images/bglines.png);
        }
        h1 { font-weight: normal; font-size: 42px; }
        h1, p, pre, video, h2, figure, h3, ol { margin: 0 0 15px 0; }
        h2 { margin-top: 80px; }
        h1 { margin-bottom: 40px; }
        li { margin: 0 0 5px 20px; }
        article { background: white; padding: 10%; }
        pre { display: block; padding: 10px; background: #eee; overflow-x: auto; font: 12px Monaco, MonoSpace; }
    
        img { max-width: 100%; }
    
        .videoWrapper {
            position: relative;
            padding-bottom: 56.25%;
            padding-top: 25px;
            height: 0;
        }
        .videoWrapper iframe,
        .videoWrapper object,
        .videoWrapper embed {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
        }
        video {
          width: 100%    !important;
          height: auto   !important;
        }
        figure { display: block; background: #eee; padding: 10px; }
        figcaption { display: block; text-align: center; margin: 10px 0; font-style: italic; font-size: 14px; orphans: 2; }
      </style>
    </head>
    
    <body>
    <?
    if(isset($_GET['url'])){
    $vid = "movies/".$_GET['url'];  
    $pos = "movies/".$_GET['pic'];
    if($pos == "movies/ng.png"){
        $cap = "Animation - Funny Play Station 3 Nigerin video clip";
    }
    if($pos == "movies/wg.png"){
        $cap = "Jordan Armsterdam - The flight of the Wild Geese";
    }
    ?>
    <figure>
        <video src="<?php echo $vid;?>" controls poster="<?php echo $pos;?>"></video>
        <figcaption><?php echo $cap; ?></figcaption>
    </figure>
    
    <?php }else{ echo "You must be a paid Student in order to watch video tutorial!"; }?>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
    <script>
        var $allVideos = $(".js-resize"),
            $fluidEl = $("figure");
    
        $allVideos.each(function() {
    
          $(this)
            // jQuery .data does not work on object/embed elements
            .attr('data-aspectRatio', this.height / this.width)
            .removeAttr('height')
            .removeAttr('width');
    
        });
    
        $(window).resize(function() {
    
          var newWidth = $fluidEl.width();
          $allVideos.each(function() {
    
            var $el = $(this);
            $el
                .width(newWidth)
                .height(newWidth * $el.attr('data-aspectRatio'));
    
          });
    
        }).resize();
    </script>
    
    </body>
    
    </html>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多