Current location: Hot Scripts Forums » Programming Languages » PHP » failed to open stream: HTTP request failed

failed to open stream: HTTP request failed

Reply
  #1 (permalink)  
Old
Wannabe Coder
 
Join Date: Jul 2006
Posts: 228
Thanks: 0
Thanked 0 Times in 0 Posts
failed to open stream: HTTP request failed

Hi all. I try to run the following script that read image url from rss xml and display it but when image url has space on it it fails as shown below(trows garbage as output with error).If i copy and paste that url the image displays in the browser but for some reason it trows error on the page if it is called with this php script. I be happy if some one help me deal with image names that has space on them.Thanks




Error:
Code:
<br />
<b>Warning</b>:  imagecreatefromjpeg(./david bob.jpg): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
 in <b>/home/www/script.php</b> on line <b>27</b><br />
<br />
<b>Warning</b>:  imagecopymerge(): supplied argument is not a valid Image resource in <b>/home/www/script.php</b> on line <b>28</b><br />
PNG


IHDRB IDATxy|]Wu?]^I5Y[`Y;s8	$!!$_)B/)Ёh?@[t miZ$JN!vl2cϓdk5[gr~Zs

......
.....

php code:

Code:
<?php


	header("Cache-Control: no-cache, must-revalidate");
	header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  	header ("Content-type: image/png");

  	$background = imagecreatefrompng("./backround_image.png");

$xml = file_get_contents("./rss.php?xml=true");

preg_match_all('/<(artist|song|image)>([^<]+)<\/\\1>/i', $xml, $matches);

list($artist, $song, $imageurl) = $matches[2];

//echo $artist;
//echo $song;
//echo $imageurl;



  	$insert = imagecreatefromjpeg($imageurl);
  	imagecopymerge($background,$insert,47,50,0,0,80,80,100);

......
Reply With Quote

Featured Marketplace Scripts (view more)

  #2 (permalink)  
Old
Nico's Avatar
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,129
Thanks: 12
Thanked 93 Times in 89 Posts
Try using rawurlencode().
PHP Code:

$insert imagecreatefromjpeg(rawurlencode($imageurl)); 

Reply With Quote
  #3 (permalink)  
Old
Wannabe Coder
 
Join Date: Jul 2006
Posts: 228
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by Nico View Post
Try using rawurlencode().
PHP Code:

$insert imagecreatefromjpeg(rawurlencode($imageurl)); 

Thanks for u reply.I get this part of out put :

<br />
<b>Warning</b>: imagecreatefromjpeg(http%3A%2F%2www.localhost.com% 2Fsong_images%2bob%20marly.jpg
): failed to open stream

i get this prolem only when the song name has spaces on them not the url.Url part is static mostly. Using rawurlencode i get error with song names that does not have space too!

Last edited by method; 02-22-07 at 06:44 AM.
Reply With Quote
  #4 (permalink)  
Old
UnrealEd's Avatar
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 27 Times in 27 Posts
try using str_replace():
PHP Code:

$insert imagecreatefromjpeg(str_replace(' ''%20'$imageurl)); 

Reply With Quote
  #5 (permalink)  
Old
Wannabe Coder
 
Join Date: Jul 2006
Posts: 228
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by UnrealEd View Post
try using str_replace():
PHP Code:

$insert imagecreatefromjpeg(str_replace(' ''%20'$imageurl)); 

Thanks this solved part of the problem by using :


$insert = imagecreatefromjpeg(str_replace(' ', '%20', $imageurl));

But when i name of images are like this it failes again. Could u help me fix these and all other errors all together?

names that i get error:
Code:
dj%20dynamite%20&amp;%20dj%20diez.jpg

cindy &amp; stacy.jpg
Reply With Quote
  #6 (permalink)  
Old
UnrealEd's Avatar
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 27 Times in 27 Posts
the code Nico suggested should work. The one i gave was just a simple workaround for your problem.
Are you sure that the file exists, otherwise you will always get "failed to open stream".
You should be consistent in naming your files. try replacing all whitespaces in filenames with underscores. that way you don't get those irritating names you posted above.

UnrealEd
Reply With Quote
  #7 (permalink)  
Old
Wannabe Coder
 
Join Date: Jul 2006
Posts: 228
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by UnrealEd View Post
the code Nico suggested should work. The one i gave was just a simple workaround for your problem.
Are you sure that the file exists, otherwise you will always get "failed to open stream".
You should be consistent in naming your files. try replacing all whitespaces in filenames with underscores. that way you don't get those irritating names you posted above.

UnrealEd
Thanks for your reply. Yes the image files exist. The image files comes from remote radio station feed and it is not in my controle to select good names with it. If i just copy and past the same url in to browser the image gets displayed. But for some reason this php script can not display image files which has those & % characters!! Now if a image name has sapce on it i do not get errors But if they have & or % then i get these errors.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL failed to open file error.... Clark_Kent Database 1 06-10-07 07:32 AM
HTTP Request Barnz1986 PHP 5 08-17-06 05:03 PM
Help with my config.php and base path...getting error: failed to open stream: ... shannonw PHP 2 07-07-06 12:38 PM
Removing "Warning: main(watever.php): failed to open stream" coolmark18 PHP 2 12-04-05 06:58 PM
Is there most correct way to save whole http request as xml bdimych PHP 0 12-10-04 08:05 PM


All times are GMT -5. The time now is 03:40 PM.
vBulletin® Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.