How can the unlink() function in PHP be used to specify a path for file deletion?
To use the unlink() function in PHP to specify a path for file deletion, you need to provide the full path to the file you want to delete. This is important because unlink() requires the full path to the file in order to delete it successfully. By specifying the full path, you ensure that the correct file is targeted for deletion.
$file_path = '/path/to/your/file.txt';
if (file_exists($file_path)) {
unlink($file_path);
echo 'File deleted successfully.';
} else {
echo 'File does not exist.';
}
Keywords
Related Questions
- When storing query results in an array in PHP, what considerations should be taken into account to ensure efficient memory usage?
- What are common pitfalls when using & in PHP code and how can they be avoided?
- How can CSS be utilized to improve the formatting and styling of image displays generated by PHP scripts?