SunQuest
 
           PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
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  
Old November 2nd, 2003, 08:56 AM
nkunicki nkunicki is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 32 nkunicki User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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");
	}
?>

Reply With Quote
  #2  
Old November 2nd, 2003, 09:50 AM
manoloweb manoloweb is offline
Moderated
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Monterrey MX
Posts: 49 manoloweb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Hello,

You should be able to do that using :
PHP Code:
 $myfile=fopen("http://www.yoursite.com/mp3/song1.mp3");
$myfileHeaders=file_get_wrapper_data($myfile); 
print_r ($myfileHeaders); 


(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.

Reply With Quote
  #3  
Old November 2nd, 2003, 10:00 AM
nkunicki nkunicki is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 32 nkunicki User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
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?

Reply With Quote
  #4  
Old November 2nd, 2003, 10:30 AM
manoloweb manoloweb is offline
Moderated
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Monterrey MX
Posts: 49 manoloweb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Wow,

Maybe it need a special configuration, have you tried $http_response_header()?

Reply With Quote
  #5  
Old November 2nd, 2003, 10:39 AM
manoloweb manoloweb is offline
Moderated
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Monterrey MX
Posts: 49 manoloweb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
I found this in my CHM manual's user contributed notes:

PHP Code:
 $file = new GetWebObject("de.php.net"80"/");
 
$data $file->get_header();
 echo 
$data["status"];
 echo 
$data["Content-Type"];
 
 echo 
$file->get_content();
class 
GetWebObject
{
 var 
$host  "";
 var 
$port  "";
 var 
$path   "";
 var 
$header = array();
 var 
$content "";
 function 
GetWebObject($host$port$path)
 {
   
$this->host $host;
   
$this->port $port;
   
$this->path $path;
   
$this->fetch();
 }
 
 function 
fetch()
 {
   
$fp fsockopen ($this->host$this->port);
   
   if(!
$fp)
   { die(
"Could not connect to host.");}
   
   
$header_done=false;
   
   
$request "GET ".$this->path." HTTP/1.0\r\n";
   
$request .= "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)\r\n";
   
$request .= "Host: ".$this->host."\r\n";
   
$request .= "Connection: Close\r\n\r\n";
   
$return '';
   
   
fputs ($fp$request);
   
   
$line fgets ($fp128);
   
$this->header["status"] = $line;
   
   while (!
feof($fp))
   {
     
$line fgets $fp128 );
     if(
$header_done)
     { 
$this->content .= $line;}
     else
     {
       if(
$line == "\r\n")
       { 
$header_done=true;}
       else
       {
         
$data explode(": ",$line);
         
$this->header[$data[0]] = $data[1];
       }
     }
   }
   
   
fclose ($fp);
 }
 
 function 
get_header()
 { return(
$this->header);}
 
 function 
get_content()
 { return(
$this->content);}


Reply With Quote
  #6  
Old November 2nd, 2003, 10:52 AM
nkunicki nkunicki is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 32 nkunicki User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 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");
	}

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Check Remote File MIME Type Using PHP


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway