PDA

View Full Version : New File


johntbailey
08-03-2006, 11:28 PM
I'm trying to dynamically specify the name of the new file to be created (server side) by passing the file name into php.

I'm using (which works when I define the filename inside the php):


//$filename = "images.xml";
$raw_xml = file_get_contents("php://input");

print $raw_xml;

$fp = fopen($filename, "w");
fwrite($fp, $raw_xml);
fclose($fp);


I've tried doing this www.myurl.com/newfile.php?filename=new.xml

Any ideas?

apoole7
08-04-2006, 12:03 AM
I'm sure that there are cleaner/better ways, but this has worked for me:
php net explains this quite well - here (http://uk.php.net/fopen)

$raw_xml = file_get_contents("php://input");
print $raw_xml;

$filename = $_GET['filename'];
touch($filename);
chmod($filename, 0777); //leave out or change as required
if(is_writable($filename)){
$fp = fopen($filename,'a+');
flock($fp, LOCK_EX);
fwrite($fp,$raw_xml);
flock($fp,LOCK_UN);
fclose($fp);
echo "<br />Success ".$filename." created & written<br />\n";
}else{
echo "a problem with ".$filename."<br />\n";
}

Cheers

Andy