-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXmlGetImage.php
34 lines (28 loc) · 989 Bytes
/
XmlGetImage.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
/*
* XmlGetImage.php
* Dataservis XML dosyasındaki ürünleri okur ve resimleri belirtilen klasöre kaydeder
* XML adresleri https://www.dataservis.net/xml/ adresinde yer almaktadır
*/
// XML içeriğini çekelim
$xml = simplexml_load_file('[XML-ADRES]');
// Tüm ürünler için
foreach($xml->Urun as $urlUrun)
{
// Tüm görseller çekilsin
foreach($urlUrun->UrunGorsel->children() as $url)
{
$filename = basename($url); // dosyayı yakala
if(file_exists('images/'.$filename))
{
// Dosya mevcutsa mesaj yaz geç
echo $urlUrun->UrunKod." > <strong>$filename</strong> mevcut<br/>";
} else {
// Dosya mevcut değilse kaydet
$img = file_get_contents($url); // urlden resmi al
file_put_contents('images/'.$filename, $img); // dosyayı yarat ve resmi koy, yazılabilir durumda images klasörünün bulunması gereklidir, klasör adı isteğe göre değişebilir.
echo $urlUrun->UrunKod." > <strong>$filename</strong> oluşturuldu <br/>";
}
}
}
?>