How can the successful saving of a file in PHP be confirmed, especially when dealing with XML documents?
When saving a file in PHP, especially XML documents, it is important to confirm that the file was saved successfully to avoid any data loss or corruption. One way to do this is by using the `file_put_contents` function, which returns the number of bytes written to the file. By checking if this value is greater than 0, we can confirm that the file was saved successfully.
$xmlData = "<example><data>Some data</data></example>";
$filename = "example.xml";
if(file_put_contents($filename, $xmlData) !== false) {
echo "File saved successfully!";
} else {
echo "Error saving file.";
}