【发布时间】:2011-08-26 20:22:25
【问题描述】:
我有带有简单 PHP 上传器的 Flash 照片库。
在 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>
有什么建议吗?
附言。对不起我的英语不好:)
问候,阿图尔。
【问题讨论】: