PDA

View Full Version : Write xml to folder


pdarley
02-13-2008, 04:26 PM
I have no problem writing an xml file to the local directory my write_xml.php is in. But I am trying to hardcode a folder and having trouble. My code is below.

<?php
// Recieving the flash variables.
$xml = $_POST['xml'];
//$folder = "xml"
$folder = $_POST['folder'];

if(!is_dir($folder))
mkdir($folder, 0755);

$myFile = "http://www.mydomain.com/xml/audio.xml";
$fh = fopen($myFile, 'w') or die("can't open file");

fwrite($fh, $xml);
fclose($fh);
?>

Can anyone please advise how to write the xml file into a specific folder?

inhan
02-14-2008, 03:05 AM
Did you check http://tr2.php.net/manual/en/function.mkdir.php ? There are suggestions from contributors about pathing.

pdarley
02-15-2008, 04:12 PM
I came up with a solution. This worked.

<?php

$xml = $_POST['xml'];
$folder = $_POST['folder'];

if(!is_dir($folder)) {
mkdir($folder, 0755);
}

$myFile = "audio.xml";
$fh = fopen($myFile, 'w') or die("can't open file");

fwrite($fh, $xml);
fclose($fh);

rename($myFile, $folder . '/' . $myFile);

?>