Hi all . could any one show me how i can read the first 100 k of a remote mp3 file but not the whole file. i be happy if an expert show me how.Thanks
Printable View
Hi all . could any one show me how i can read the first 100 k of a remote mp3 file but not the whole file. i be happy if an expert show me how.Thanks
From the manual:
Use fopen(string filename, string mode), which returns a resource handle, to open the remote file (assuming that such a feature is enabled within your PHP).Quote:
string fread ( resource handle, int length )
fread() reads up to length bytes from the file pointer referenced by handle. Reading stops when up to length bytes have been read, EOF (end of file) is reached, or (for network streams) when a packet becomes available, whichever comes first.
PHP Code:$fp = fopen('http://remote/file.mp3', 'r');
$data = fread($fp, 100 * 1024);
Many thanks for u reply. I am running php on my localhost server . How i know if it is enabled ? could u tell me how to enable it ?
Furthermore , how i can confirm that the partion of the file is downloaded?where it will be stored? The reason is that i want to use getId3 with that mp3 file and get its tag info.So i be happy if u tell me how i can refrence that partial downloaded file.Thanks
Just test it and see. To enable it, you'd have to configure your PHP and if you don't know how to do that, you probably don't have access to do so.Quote:
Originally Posted by tony007
It's stored in $data...Quote:
Originally Posted by tony007
Thank u for u reply. I tried it now i get this error :Quote:
Originally Posted by kasracer
Warning: fopen(http://www.remotesite.com/song.mp3) [function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in \getid3\remote3.php on line 5
Fatal error: Call to a member function analyze() on a non-object in \getid3\remote3.php on line 13
Bold parts are line 5 and 11
I even tried this but i got error again:Code:<?
if ($fp1 = fopen('http://www.remotesite.com/song.mp3', 'rb')) {
$tempname = tempnam('/tmp', 'foo');
if ($fp2 = fopen($tempname, 'wb')) {
fwrite($fp2, fread($fp, 102400));
fclose($fp2);
}
fclose($fp1);
}
$getID3->analyze($tempname); line 13th
?>
Error:Code:<?
$fp = fopen('http://www.remoteserver.com/1.mp3', 'r');
$data = fread($fp, 100 * 1024);
$getID3->analyze($data);
?>
I be happy if u let me know how to fix it.thanksCode:Warning: fopen(http://www.remoteserver.com/1.mp3 ) [function.fopen]: failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request in \getid3\remote3.php on line 6
Warning: fread(): supplied argument is not a valid stream resource in \getid3\remote3.php on line 7
Fatal error: Call to a member function analyze() on a non-object in \getid3\remote3.php on line 9