I'm trying to modify a drag and drop uploader. Once the file has been uploaded it shows up on right-hand side. I want to add a description field for each file on the right-hand side. My XML is being written by checking the directory. I am able to save each file's descriptions to the XML. But it overwrites all of my descriptions with "-
" if I were to remove or upload a file to the directory. What I'm try to do is upload or remove new item without overwriting my older items descriptions.
PHP- for remove and upload. this function is checking the directory and adding nodes to XML for each file that been uploaded.
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 adding the descriptions to each item.
$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>