|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
Check Remote File MIME Type Using PHP
Hi, I'm making a script which takes a the URL of an MP3 file from the querystring and streams it. It works as below, but I want to be able to check the MIME type of the specified file before streaming it. Any help appreciated. Here's the code I have at the moment:
Code:
<?php
$MP3File = $_GET["filename"];
if ($MP3File != "") {
if (@fclose(@fopen($MP3File, "r"))) {
header("Content-type: audio/x-mpegurl");
print($MP3File);
} else {
print("Error: Specified Filename Not Found");
}
} else {
print("Error: No Filename Specified");
}
?>
|
|
#2
|
|||
|
|||
|
Hello,
You should be able to do that using : PHP Code:
(I think you need PHP 4.3.X +) Hope it helps ![]()
__________________
The deal is not to know everything, but to know the email of the one who does. |
|
#3
|
|||
|
|||
|
Hi, thanks for the reply. I get this when I run that code:
Fatal error: Call to undefined function: file_get_wrapper_data() in c:\apache\apache\htdocs\music_headers.php on line 4 I'm running PHP 4.3.2, any ideas? |
|
#4
|
|||
|
|||
|
Wow,
Maybe it need a special configuration, have you tried $http_response_header()? |
|
#5
|
|||
|
|||
|
I found this in my CHM manual's user contributed notes:
PHP Code:
|
|
#6
|
|||
|
|||
|
Thanks for the help guys, but I managed it with this:
Code:
$FileString = $_GET["filename"];
if ($FileString != "") {
$FilePointer = fopen($FileString, "r");
if (!$FilePointer) {
die("Error: Could Not Open Specified Filename");
} else {
$FileHeaders = stream_get_meta_data($FilePointer);
$IsMP3File = 0;
foreach ($FileHeaders as $FileHeader) {
foreach ($FileHeader as $HeaderValue) {
if (strpos(strtolower($HeaderValue), "audio/mpeg")) {
$IsMP3File = 1;
}
}
}
if ($IsMP3File == 1){
header("Content-type: audio/x-mpegurl");
print($FileString);
} else {
die("Error: The Specified Filename Is Not In MP3 Format");
}
}
} else {
die("Error: No Filename Specified");
}
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > Check Remote File MIME Type Using PHP |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|