У меня есть флэш-фотогалерея с простым загрузчиком PHP.
В файл uploader.php я добавил код, который сохраняет последние 20 добавленных фотографий в файл XML.
Скрипт для сохранения данных вXML-файл, который я уже сделал, и XML-структура выглядит следующим образом:
<images>
<image thumb="/content/photos/tn_PICTURE1.jpg" image="/content/photos/PICTURE1.jpg" name="PICTURE1"/>
<image thumb="/content/photos/tn_PICTURE2.jpg" image="/content/photos/PICTURE2.jpg" name="PICTURE2"/>
<image thumb="/content/photos/tn_PICTURE3.jpg" image="/content/photos/PICTURE3.jpg" name="PICTURE3"/>
...
<image thumb="/content/photos/tn_PICTURE20.jpg" image="/content/photos/PICTURE20.jpg" name="PICTURE20"/>
</images>
Часть файла uploader.PHP:
$domtree = new DOMDocument('1.0', 'UTF-8');
$domtree->load("new_files.xml");
$root = $domtree->documentElement;
$currentImage = $domtree->createElement("image");
$currentImage = $root->appendChild($currentImage);
$thumb = $domtree->createAttribute("thumb");
$currentImage->appendChild($thumb);
$thumbValue = $domtree->createTextNode($thumbnail);
$thumb->appendChild($thumbValue);
$imagelink = $domtree->createAttribute("image");
$currentImage->appendChild($imagelink);
$imageValue = $domtree->createTextNode($fullpath);
$imagelink->appendChild($imageValue);
$imagename = $domtree->createAttribute("name");
$currentImage->appendChild($imagename);
$imagenameValue = $domtree->createTextNode($imageName);
$imagename->appendChild($imagenameValue);
$domtree->save("new_files.xml");
Что я хочу сделать?
Когда в xml-файле содержится более 20 изображений, я хочу, чтобы этот скрипт автоматически удалял последний (самый старый) и помещал самый новый в качестве первого.Таким образом, результат будет выглядеть так:
<images>
<image thumb="/content/photos/tn_PICTURE21.jpg" image="/content/photos/PICTURE21.jpg" name="PICTURE21"/>
<image thumb="/content/photos/tn_PICTURE1.jpg" image="/content/photos/PICTURE1.jpg" name="PICTURE1"/>
<image thumb="/content/photos/tn_PICTURE2.jpg" image="/content/photos/PICTURE2.jpg" name="PICTURE2"/>
...
<image thumb="/content/photos/tn_PICTURE19.jpg" image="/content/photos/PICTURE19.jpg" name="PICTURE19"/>
</images>
Есть предложения?
Ps.Извините за мой плохой английский:)
С уважением, Артур.