1

I want to create a script that will display video if the file format of file uploaded by user is video file or image if the file format is image file, I don't have problem with the query and the extension function, but I'm having problem with displaying the result of the image and playing the video, below is the code

    <?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">';
        }
   ?>
benyusouf
  • 325
  • 2
  • 6
  • 17
  • 2
    In you last echo there is PHP, there shouldn't be. And if the syntax highlighting of StackOverflows `` is not correct, maybe you should check it before posting. Also, try being consistent with `"` and `'`. – Casper Spruit Mar 22 '17 at 08:43
  • I have remove the php in src attribute, and between single quote and double quote which one should I use for echo and which one should I use for html attributes? – benyusouf Mar 22 '17 at 08:55
  • `When to use single or double quotes in php html` Try googling it – Casper Spruit Mar 22 '17 at 08:59
  • I google search but I was lost, please can you help me explain – benyusouf Mar 22 '17 at 11:12

1 Answers1

1

You can try it like this.

<?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'>";
}
?>

If you're interested you could read up on what went wrong, so it won't happen again.

Not saying these articles/posts are the best out there on the subjects

Community
  • 1
  • 1
Casper Spruit
  • 944
  • 1
  • 13
  • 31