我正在尝试修改拖放上传器。上传文件后,它会显示在右侧。我想在右侧为每个文件添加一个描述字段。我的 XML 正在通过检查目录来编写。我能够将每个文件的描述保存到 XML。-
但如果我要删除或上传文件到目录,它会用“”覆盖我的所有描述。我正在尝试做的是上传或删除新项目而不覆盖我的旧项目描述。
PHP- 用于删除和上传。 此功能检查目录并将节点添加到每个已上传文件的 XML。
if ( $handle = opendir( $path_to_image_dir ) )
{
while (false !== ($file = readdir($handle)))
{
if ( is_file($path_to_image_dir.'/'.$file) && $file != "." && $file != ".." && $file != "Thumb.db" && $file != "Thumbs.db" && $file != ".DS_Store" )
{
list( $width, $height ) = getimagesize($path_to_image_dir.'/'.$file);
$image = $xml_generator->addChild('image');
$image->addChild('id', 'file'.$i++);
$image->addChild('name', $file);
$image->addChild('width', $width);
$image->addChild('height', $height);
$image->addChild('description', '-');
}
}
closedir($handle);
}
// Write the XML File to a file.
$xml_generator->asXML('../file.xml');
Description.Php将描述添加到每个项目。
$filename = "../file.xml";
//value form the pop up description form.
$description = $_POST['description'];
// id of input from the write rightside list.
$hid = $_POST['fileID'];
$xml->image ->description = $description;
$xml = simplexml_load_file($filename);
foreach($xml->image as $image)
{
// matching the xml id to input id, and then updating the description.
if ($image->id == $fileID)
{
$image->description = $description;
}
}
$xml->asXML($filename);
XML
<images>
<image>
<id>file0</id>
<name>image1.jpg</name>
<height>1435</height>
<width>2551</width>
<description>-</description>
</image>
<image>
<id>file1</id>
<name>Image2.jpg</name>
<height>1435</height>
<width>2551</width>
<description>-</description>
</image>
</images>