Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error : failed to open stream:http request failed

Status
Not open for further replies.
Apr 28, 2006
69
NL
Hi all .I have the following php script when i run it i get the following error. The remote file is downloadable in remote server and also in my php localhost the open is set to on but i still get the following errors . I be happy if some one tell how me how to fix it.Thanks

Code:
Warning: fopen([URL unfurl="true"]http://www.remotesite.com/song.mp3)[/URL] [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
Code:
<?

[b]if ($fp1 = fopen('[URL unfurl="true"]http://www.remotesite.com/song.mp3',[/URL] 'rb')) { [/b]
  $tempname = tempnam('/tmp', 'foo'); 
  if ($fp2 = fopen($tempname, 'wb')) { 
    fwrite($fp2, fread($fp, 102400)); 
    fclose($fp2); 
  } 
  fclose($fp1); 
} 
[b]$getID3->analyze($tempname); [/b] line 13th



?>
 
does the remote site use sessions or cookies or some other access control method? are you certain the mp3 is directly retrievable?
 
jpadie thank u for u reply. well yes the mp3 is downloadable. by rightclicking and save as so i assume the permissions are not the problem. I even tried it to point open to a mp3 in my localhost server and i get the same error!! both songs can be dowloaded if u put them in address bar. I be happy if i get this fixed.Thanks
 
then the problem is with your own server (the one that you are running php from). you have not got the allow_url_fopen turned on. This can only be turned on from the php.ini file.
Code:
allow_url_fopen On

if your server runs php as a cgi put the above code in a text file, upload it to the directory in which you are running the remote3 script and rename it as php.ini.

the second error, of course, flows directly from the first.

from the grammar, it appears that you asked this question on the getid3 support site.


did the answer there not work for you?
 
allow_url_fopen is on i checked it from my php.ini but still same error!!
 
are you sure it is the right php.ini? what does a call to phpinfo() report?
 
thank u for u reply. I checked phpinfo by loading it and i saw this :

allow_url_fopen On On for both local value and master value. Could u try at your webserver and see if it works?Thanks
 
sure. can you provide a url to test with?
 
well i am running localhost webserver with php support and testing it . do not u have localhost webserver? i posted the code up .Thanks
 
sorry - i meant a url for a remote mp3 file.
 
man i keep testing in in my local host it does not work there and i am dam sure it will not in remote servers as well.
 
works for me.

of course you have to change this line:
Code:
fwrite($fp2, fread($fp, 102400));
to
Code:
fwrite($fp2, fread($fp1, 102400)); //NOT $fp but $fp1
 
well i tried it no error but i do not see any file in temp folder!! if it worked it should have dowloaded part of the file but i do not see it !
 
i suspect it may be a permissions issue now. try this:

Code:
if ($fp1 = fopen('[URL unfurl="true"]http://www.remotesite.com/song.mp3',[/URL] 'rb')) {
  $tempname = tempnam('/tmp', 'foo');
  if ($fp2 = fopen($tempname, 'wb')) {
    fwrite($fp2, fread($fp1, 102400));
    fclose($fp2);
  } else {die ("you do not have write permissions for this directory");}
  fclose($fp1);
}
 
I just get a white page and when i check temp folder that i alrad created in same folder as the script is i do not see any thing !! It is not permission problem since the song is my localhost!!
 
It is not permission problem since the song is my localhost!!

this is not wholly relevant. you need to make sure that the user that the web process runs under has write permissions to the /tmp folder. in linux chmod the folder to 0777 and in windows right click on the /tmp folder, select security and assign write permissions to the IUSR_[MACHINE NAME] account.
 
Thank u for u reply. I am using apache on windows . How to setup permission on that ?
 
go to the /tmp folder and examine the security settings. add whichever user you are running apache under to the list of authorised users and give it write permissions.

but just in case it is not a permission issue let's put some more footprinting into the code snip:

Code:
$fp1 = fopen('[URL unfurl="true"]http://www.remotesite.com/song.mp3',[/URL] 'rb')
 or die ("can't open remote site");
$tempname = tempnam('/tmp', 'foo');
echo "<br/> tempname is $tempname <br/>";
$fp2 = fopen ($tempname, "wb") 
  or die ("<br/>unable to open $tempname for writing<br/>");    
$contents = fread ($fp1,102400);
echo "<br/>contents to be written to $tempname are $contents<br/>";
fwrite($fp2, $contents)
  or die ("<br/>unable to write data to $tempname<br/>");
fclose($fp2);
fclose($fp1);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top