The problem is redirecting the original URL. You want to catch the URL to which it redirects, try using the headers, and then get the base name ($ redirect_url) as the name of your file.
+1 for Robbie using CURL.
If you run (from the command line)
[ username@localhost ~]$ curl http://priceinindia.org/muzicpc/48.php?id=415508 -I HTTP/1.1 302 Moved Temporarily Server: nginx/1.0.10 Date: Wed, 19 Sep 2012 07:31:18 GMT Content-Type: text/html Connection: keep-alive X-Powered-By: PHP/5.3.10 Location: http://lq.mzc.in/data48-2/37202/Appy_Budday_(Videshi)-Santokh_Singh(www.Mzc.in).mp3
You can see that the location header is the new URL.
in php try something like
$ch = curl_init('http://priceinindia.org/muzicpc/48.php?id=415508'); curl_setopt($ch, CURLOPT_HEADER, 1); // return header curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); // dont redirect $c = curl_exec($ch); //execute echo curl_getinfo($ch, CURLINFO_HTTP_CODE); // will echo http code. 302 for temp move echo curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); // url being redirected to
You want to find part of the header location. not sure if the installation is really true.
EDIT 3..or 4? Yes, I see what is happening. You really want to follow location URLs and then echo the effective URL without downloading the file. try it.
$ch = curl_init('http://priceinindia.org/muzicpc/48.php?id=415508'); curl_setopt($ch, CURLOPT_NOBODY, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); $c = curl_exec($ch); //execute echo curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); // url being redirected to
When I run this my output,
[ username@localhost ~]$ php test.php http://lq.mzc.in/data48-2/37202/Appy_Budday_(Videshi)-Santokh_Singh(www.Mzc.in).mp3