I need to download all photos about estates from an XML to save on the server. Every estate child in the XMl has a general section with all information and then a node called Foto (estate's photos) and another one for plans (Planimetria). The link of every image is structured as is:
<Link>http://www.site.it/ImageView.ashx?id=[photoID]&reduce=1438[can be set as I want es: 1000, 960, 1080]</Link>
I need to call it inside the $url_photo and $url_plan so I can read the photoID from XML and set resolution (1438,1000,960) with a global variable.
This is my code:
   <?php
    $xml = simplexml_load_file("Schede.xml"); // your xml
    $path = '/mnt/c/Users/Giuseppe/Desktop/FotoTest/';
    $i = 1;
    $resolution = '1000';
        // Estate Image
        foreach($xml->CR03_SCHEDE as $estate){
            //if((string) $estate['ELIMINATO'] = "NO"){
                echo "\nEstate n $i Images\n";
                foreach($estate->Foto->CR04_SCHEDE_FOTO as $photo){
                    $url_photo = (string) $photo->Link;
                    $filename_photo = basename($photo->CR04_FILENAME); // get the filename
                    if(file_exists($path . $filename_photo)) {
                        echo "file $filename_photo already exists \n";
                    } 
                    else {
                        $img_photo = file_get_contents($url_photo); // get the image from the url
                        file_put_contents($path . $filename_photo, $img_photo); // create a file and feed the image
                        echo "file $filename_photo created \n";
                    }
                }
                // Plans
                echo "\nEstate n $i plans\n";
                foreach($estate->Planimetria->CR04_SCHEDE_FOTO as $plan) {
                    $url_plan = (string) $plan->'http: // www.site.it/ImageView.ashx?id=' . $plan->ID . '&reduce=' . $resolution; //$plan->Link;
                    $filename_plan = basename($plan->CR04_FILENAME);
                    if(file_exists($path . $filename_plan)) {
                        echo "file planimetry $filename_plan already exists \n";
                    }
                    else {
                        $img_plan = file_get_contents($url_plan); // get the image from the url
                        file_put_contents($path . $filename_plan, $img_plan); // create a file and feed the image
                        echo "file planimetry $filename_plan created \n";
                    }
                }
                $i++;
/*}
            else{
                echo "$estate->attributes(Riferimento)"."Deleted\n";
            }*/
        }
    ?>
I also have a problem with the first if commented:
if((string) $estate['ELIMINATO'] = "NO")...
Eliminato is an attribute of CR03_SCHEDE but the script won't read it and in any case go inside the if. The complete XML has about 70/80 properties and the foreach works well to download all images, but I need that it should download the only one that has that attribute equals to NO
This is the example of XML (only one estate): link
Thanks to all
 
    