file_put_contents creates corrupt image

tech

New Member
I am trying to parse an RSS feed and download all of the images for each item. I am looping through each item and doing the following to save the image:\[code\]$url = str_replace(' ', '%20', $itemRSS['image']);$rand = rand(1111, 99999999);$img = $_SERVER['DOCUMENT_ROOT'].'/prod_images/'.$rand.'.jpg';file_put_contents($img, file_get_contents($url));\[/code\]There are approximately 100 items in the RSS feed and 100 images are created on the server but when I download them all only a few work, the rest are invalid. They are all jpg's incase you think it's because I'm calling them all .jpg when some might not be.AHHHH thanks for everyone that commented. I have opened a corrupt one in notepad and get this:\[code\]<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><HTML><HEAD><TITLE>400 Bad Request</TITLE></HEAD><BODY><H1>Bad Request</H1>Your browser sent a request that this server could not understand.<P>The request line contained invalid characters following the protocol string.<P><P><HR><ADDRESS>Apache/1.3.37 Server at www.magicbunny.co.uk Port 80</ADDRESS></BODY></HTML>\[/code\]
 
Back
Top