0

I need to open an xml file and allow people to add entries to the file. So i need to open it with read and write access be able to insert an entry and then close it with read only access so another program (adobe bridge) cant write over the file.

2
Contributors
3
Replies
4
Views
11 Years
Discussion Span
Last Post by digital-ether
0

Use chmod to set the permissions of the file so its writable. Then open it with write access, then after you write and close the file, use chmod again to change the permissions to read only.

eg:

@chmod ($configfile, 0755);
$xml_string = file_get_contents($filepath);
read_write_to_xml($xml_string);
if ($fp = fopen($filepath, 'w')) {
     fwrite($fp, $xml_string, strlen($xml_str);
     fclose($fp);
} else {
     echo 'Cannto write to file';
}
@chmod ($configfile, 0744);

Should do it. Unless you're on windows, then chmod wouldnt make any sense.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.