How can the $_GET superglobal be used to pass information about the file to be deleted in PHP?
To pass information about the file to be deleted using the $_GET superglobal in PHP, you can include the file name as a parameter in the URL and retrieve it using $_GET['filename']. This way, you can dynamically delete the specified file based on the parameter passed in the URL.
<?php
if(isset($_GET['filename'])){
$filename = $_GET['filename'];
if(file_exists($filename)){
unlink($filename);
echo "File $filename has been deleted.";
} else {
echo "File $filename does not exist.";
}
} else {
echo "No file specified for deletion.";
}
?>
Keywords
Related Questions
- How can the file_get_contents function be utilized to manipulate the contents of an XML file before parsing it with simplexml_load_file?
- How can namespaces be effectively used to streamline the inclusion of classes from different directories and eliminate the need for repetitive require_once statements in PHP?
- What are the potential pitfalls of writing directly to an XML file without proper formatting?