Play Video From Folder
I am trying to make a simple streaming site. That will pay a video from a folder. (mp4). The tricky part is I want to change the video everyday but not the code. So Im wondering if
Solution 1:
Try something like this, assuming there is only one video with the given extension in said folder (otherwise it will get the last occurring file with that extension):
$myVideoDir = '/videos';
$extension = 'mp4';
$videoFile = false;
foreach(scandir($myVideoDir) as $item) {
if ( $item != '..' && $item != '.' && !is_dir($item) ) {
$ext = preg_replace('#^.*\.([a-zA-Z0-9]+)$#', '$1', $item);
if ( $ext == $extension )
$videoFile = $item;
}
}
if ( !!$videoFile ) {
echo '
<video id="dep" class="center" width="900" height="720" controls>
<source src="'.$myVideoDir.'/'.$videoFile.'" type="video/mp4">
</video>
';
}
Solution 2:
$myVideoDir = '/videos';
$extension = 'mp4';
$videoFile = false;
foreach(scandir($myVideoDir) as $item) {
if ($item != '..' && $item != '.' && !is_dir($item)) {
$ext = preg_replace('#^.*\.([a-zA-Z0-9]+)$#', '$1', $item);
if ($ext == $extension) $videoFile = $item;
}
}
if (!!$videoFile) {
echo ' <video id="dep" class="center" width="900" height="720" controls> <source src="'.$myVideoDir.
'/'.$videoFile.
'" type="video/mp4"> </video> ';
}
Post a Comment for "Play Video From Folder"