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
- Are there any specific configurations or settings within Xampp that need to be adjusted to ensure smooth operation of MySQL?
- What are some best practices for handling cookies in PHP to ensure proper functionality and security in a web application like Wordpress?
- How does the assignment operator in PHP affect the evaluation of logical operators?