How do you add the name of an uploaded file added to an xml file?

I made a flash object to put on my website that allows users to upload files with certain extensions ( in this case images ) and the files are uploaded to a php file named upload.php ( figures right? ) but now what I need is that when a user uploads a file for upload.php to not only move the file to the proper directory but to also add the name of that file to an xml file and at this point I am just guessing because I am terrible at php :-[
this is what I have so far (keep in mind I have pretty much no idea what I’m doing here):
[php]<?php
if (is_uploaded_file($_FILES[‘Filedata’][‘tmp_name’])) {

	$uploadDirectory = "uploads/";
	$uploadFile = $uploadDirectory . basename($_FILES['Filedata']['name']);
			
	copy($_FILES['Filedata']['tmp_name'], $uploadFile);
	$xml = simplexml_load_file('photodir.xml'); //Loads the xml file

$sxe = new SimpleXMLElement($xml->asXML()); //Creates SimpleXMLElemnt with source
$filename = basename($_FILES[‘name’]);
$imagename = $sxe->addChild(‘imagename’);
$imagename->addChild(“name”, $filename);
$sxe->asXML(‘photodir.xml’); //Saves the xml file
}
?>[/php]

I can’t help much with the XML, but I did spot an error. This line:

[php]$filename = basename($_FILES[‘name’]);[/php]

should probably be this:

[php]$filename = basename($_FILES[‘Filedata’][‘name’]);[/php]

Are you also checking the contents of the photodir.xml file to see if it is created and populated with data? Do you get any errors when running this script?

Sponsor our Newsletter | Privacy Policy | Terms of Service