Videos in HTML einbinden (Komplette PHP-Datei)

edit | delete

Autor: Ralf v.d.Mark

eingetragen: Montag, 09. Februar 2009 um 14:48 Uhr (7/2009 Kalenderwoche)

geändert: Freitag, 27. August 2021 um 15:00 Uhr (34/2021 Kalenderwoche)

Keywords: video vids einbetten einbinden wiedergeben Film download

Kategorien: HTML,

Text:

PHP-Datei um Videos in HTML einzubinden

Quellcode:  

<?php
error_reporting(0);//E_ALL

if (!empty($_GET['download'])) {
    $download = substr(strip_tags(trim($_GET['download'])), 0, 44);//Kleiner Schutz!
} else {
    $video = null;
}
if (!empty($_GET['video'])) {
    $video = substr(strip_tags(trim($_GET['video'])), 0, 44).'.mp4';//Kleiner Schutz!
} else {
    $video = null;
}

$nameDesVideos = (!empty($download) ? $download : $video);
$getVid = $_SERVER['DOCUMENT_ROOT'].'/'.$nameDesVideos;
$htmlentityNameDesVideos = htmlentities($nameDesVideos);

if (!empty($getVid) && !file_exists($getVid)) {
    //video nicht gefunden!
    exit('<h1>Das Video "'.$htmlentityNameDesVideos.'" gibt es nicht!</h1>');
        
} elseif (!empty($download)) {
    //Video-Download:
    
    //ini_set('memory_limit', '-1');//Sollte man lassen
    
    header("Cache-Control: public");
    header("Content-Type: video/mp4");
    header("Content-Length: ".filesize('.$getVid.'));
    header("Content-Description: File Transfer");
    header('Content-Disposition: attachment; filename="'.$download.'"');
    header("Content-Transfer-Encoding: binary");
    header("Content-Type: application/octet-stream");
    echo $getVid;
    /* Früher so, aber vorsicht: Apache-Timeout!
    $handle=fopen($getVid, 'rb');
    while (!feof($handle)) {
        echo fread($handle, 8192);
        flush();
    }
    fclose($handle);*/
    
} else {
    //HTML-Ausgabe mit dem eingebetten Video und dem Download-Link
    echo '<!DOCTYPE html>
    <html lang="de">
    <head>
        <base href="https://download.meridian-rheinbach.de/" />
        <link rel="Shortcut Icon" href="favicon.ico" type="image/x-icon" />
        <title>Video "'.$htmlentityNameDesVideos.'" abspielen oder herunterladen</title>
    </head>
    <body>
        <div align="center">
            <video src="/'.$video.'" controls>
                Ihr Browser kann dieses Video nicht wiedergeben.<br/>
                Dieser Film "'.$htmlentityNameDesVideos.'" zeigt eine Demonstration von Qi Gong Übungen. 
                Sie können ihn unter <a href="/showMp4.php?download='.$video.'">Download Video</a> abrufen.
            </video>
            <br><br>
            <strong>Name des Videos: "'.$htmlentityNameDesVideos.'" (<a href="/showMp4.php?download='.$video.'">Download</a>)</strong>
        </div> 
    </body>    
    </html>';
}