Hi All,

i'm having difficulties downloading about 4000 images from my php script from individual http locations.

It works as follows, every object is an xml file, and each xml file has an unknown number of attachments (images)

i loop through the xml files and then through the attachments where i use file_put_contentsto save the image to my server.

the problem is that i do get the images to my server, but strangely a lot of images get corrupt, it's always the first image of the next xml file.

any thoughts here guys?

Gr Jos

2 Years
Discussion Span
Last Post by cereal

Hi Thanx, sure here it is

$xml_files = JFolder::files($searchpath, '.xml');
$count = count($xml_files);
foreach($xml_files as $xml_file)

    $xml = simplexml_load_file(JPATH_COMPONENT_SITE.'/properties/'.date('d-m-Y').'/'.$xml_file);    

foreach($xml->RealEstateProperty->Attachments->Attachment as $attachment)


file_put_contents(JPATH_COMPONENT_SITE.'/properties/assets/'.$xml->RealEstateProperty->PropertyInfo->ID.'_'.$attachment->Index.'.jpg', fopen($attachment->URLNormalizedFile, 'r'));




It could be a timeout from remote. The default value for timeouts is defined in php.ini file, but you could create a stream context to test the download:

$options["http"] = array(
        "method"    => "GET",
        "timeout"   => 15, # seconds

fopen($attachment->URLNormalizedFile, "r", FALSE, $context);

Also check access and error logs from server and PHP.

but strangely a lot of images get corrupt, it's always the first image of the next xml file

Have you tried to manually access to the first entries of these XML files? Are these images reachable, have you tried a simple script to download just these files? Have you tried to open one of these files through an editor? Sometimes you expect binary but you find an HTML page (404 error pages for example).

By the way: why are you using fopen to get data into file_put_contents?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.