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

So what happens, in your code, when you switch between the xml files? Can you show the code?

Hi Thanx, sure here it is

$xml_files = JFolder::files($searchpath, '.xml');
$count = count($xml_files);
$counter=0;
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)
{

#DB INSERT HERE

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


}   

$counter++;

}

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?