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.

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.

thank you, unfortunately yea I am on windows at work so chmod wont work but no big deal.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.