PHP output to a .XML (Works fine, but the filename is odd)

Soldato
Joined
12 Sep 2003
Posts
11,232
Location
Newcastle, UK
Hi all,

I'm outputing some data from a Web Form to a .XML file. This works fine, I used some code from the net :p , however, it won't append the variable filename which a user enters with <filename>".xml". It just calls the file ".xml" and missus the name bit out. :confused:

Code:
if (isset($_POST['create_itinerary']))
	{	
		$xmlfileName = $_POST['xmlFileName'];
        }

...

		$default_dir = "C:/<folder1>/<folder2>/";
		$default_dir .= $xmlFileName .".xml";
		
		// Store the File
		$fp = fopen($default_dir,'w');
		fwrite($fp,$xml_doc);
		fclose($fp);

...

It gets the data via the POST method from another .php file, which has the Form on it. I don't undersand why it's not showing the $xmlFileName part before the .xml is added. The form works as it's getting other variables which a user enters and adding them into the .xml file, so why not the file name?

Thanks for any help. It's driving me crazy!
 
Thanks for the replies. :)

I will try changing the scope and post back, I never thought of that.

Oh, with regards to the indentation, no all of my code is to the left hand side but I just cut and paste that into here and tried to make it as read-able as possible by placing it in the centre. So don't worry, my code isn't all down to the right hand side. ;)

I wasn't really going for neatness, I just want to get the darn thing working first. lol.
 
I just wanted to say thanks for the help.

I tried the suggestions and it works. :D Yey!

One other question, which I hope people won't mind answering, I'm trying to now load the created .xml file and use a .xsl style sheet to output the contents onto the screen.

I have coded the .xsl fine, however, I'm stuck trying to load the .xml file because with the name being random (a variable depending on what the user enters) the name can't be set. :confused:

So it's not as if I can go,

Code:
$xml = new DOMDocument;
$xml->load('/<folder1>/<folder2>/bob.xml');

...

because that may work once, but then it may be called 'bob2' by someone else.

Can I do it so that it just looks in the folder and loads any .xml files which are in there, regardless of a name? i.e. perhaps something like,

Code:
$xml = new DOMDocument;
$xml->load('/<folder1>/<folder2>/"".xml');

...

Thanks for any help. :)
 
Back
Top Bottom