在php中显示img和视频标签

时间:2017-03-22 08:39:53

标签: php echo

我想创建一个脚本,如果文件格式是图像文件,如果用户上传的文件的文件格式是视频文件或图像,将显示视频,我对查询和扩展功能没有问题,但是我在显示图像结果和播放视频时遇到问题,下面是代码

    <?php
        $file = $row1['file'];
        $ext = pathinfo($file, PATHINFO_EXTENSION);
        if ($ext == 'mp4' || $ext == 'mov' || $ext == 'vob' || $ext == 'mpeg' || $ext == '3gp' || $ext == 'avi' || $ext == 'wmv' || $ext == 'mov' || $ext == 'amv' || $ext == 'svi' || $ext == 'flv' || $ext == 'mkv' || $ext == 'webm' || $ext == 'gif' || $ext == 'asf') {
            echo"<div class='flowplayer' data-swf='flowplayer.swf' data-ratio='0.4167'>";
              echo "<video>";
                 echo'<source type="video/webm" src="https://edge.flowplayer.org/bauhaus.webm" autoplay="autoplay">';
                 echo"<source type='video/mp4" src="https://edge.flowplayer.org/bauhaus.mp4" autoplay="autoplay">';
              echo "</video>";
           echo"</div>";
        }else{
            echo'<img src="<?php echo GW_UPLOADPATH.$row1['file']; ?>" class="img-polaroid" alt="Img" width="550px" height="500px">';
        }
   ?>

1 个答案:

答案 0 :(得分:0)

你可以这样试试。

<?php
$file = $row1["file"];
$ext = pathinfo($file, PATHINFO_EXTENSION);
if ($ext == "mp4" || $ext == "mov" || $ext == "vob" || $ext == "mpeg" || $ext == "3gp" || $ext == "avi" || $ext == "wmv" || $ext == "mov" || $ext == "amv" || $ext == "svi" || $ext == "flv" || $ext == "mkv" || $ext == "webm" || $ext == "gif" || $ext == "asf") {
    echo "<div class='flowplayer' data-swf='flowplayer.swf' data-ratio='0.4167'>";
    echo "<video>";
    echo "<source type='video/webm' src='https://edge.flowplayer.org/bauhaus.webm' autoplay='autoplay'>";
    echo "<source type='video/mp4' src='https://edge.flowplayer.org/bauhaus.mp4' autoplay='autoplay'>";
    echo "</video>";
    echo "</div>";
} else {
    echo "<img src='" . GW_UPLOADPATH . $row1["file"] . "' class='img-polaroid' alt='Img' width='550px' height='500px'>";
}
?>

如果您感兴趣,可以阅读出错的地方,这样就不会再发生了。

并不是说这些文章/帖子在主题上是最好的