1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| <?php
$file_source = 'http://user:passwort@(le domaine)/blabla/video.mov';
$size = remote_filesize($file_source,"","");
function remote_filesize($url, $user = "", $pw = "") {
ob_start();
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
if(!empty($user) && !empty($pw)) {
$headers = array('Authorization: Basic ' . base64_encode("$user:$pw"));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
$ok = curl_exec($ch);
curl_close($ch);
$head = ob_get_contents();
ob_end_clean();
$regex = '/Content-Length:\s([0-9].+?)\s/';
$count = preg_match($regex, $head, $matches);
return isset($matches[1]) ? $matches[1] : "unknown";
}
// send the right headers
header('Pragma: public');
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header('Cache-Control: must-revalidate, pre-check=0, post-check=0, max-age=0');
header('Content-Transfer-Encoding: none');
$fotpos = strrpos($rpage, ".");
if ($fotpos > 1) {
$file_ext = substr($rpage, $fotpos+1);
}
if ( !strcasecmp($file_ext, "GIF") ) {
header("Content-type: image/gif");
}
else if ( !strcasecmp($file_ext, "JPG") ) {
header("Content-type: image/jpeg");
}
else if ( !strcasecmp($file_ext, "PNG") ) {
header("Content-type: image/png");
}
else if ( !strcasecmp($file_ext, "WAV") ) {
header("Content-type: audio/x-wav");
}
else if ( !strcasecmp($file_ext, "MP3") ) {
header("Content-type: audio/mpeg");
}
else if ( !strcasecmp($file_ext, "MPG") ) {
header("Content-type: video/mpeg");
}
else if ( !strcasecmp($file_ext, "MOV") ) {
header("Content-type: video/quicktime");
header("Content-Length: " . $size);
}
else if ( !strcasecmp($file_ext, "AVI") ) {
header("Content-type: video/x-msvideo");
}
else {
header("Content-type: application/octet-stream");
header("Content-Disposition: filename=\"$binary_filename\"");
}
echo file_get_contents($file_source);
?> |
Partager