How can you specify the directory path when using the unlink function in PHP?

When using the unlink function in PHP to delete a file, you can specify the directory path by providing the full path to the file you want to delete. This ensures that the correct file is targeted for deletion. You can use the $_SERVER['DOCUMENT_ROOT'] variable to get the root directory of your server and then concatenate it with the relative path to the file you want to delete.

$file_path = $_SERVER['DOCUMENT_ROOT'] . '/path/to/file.txt';
unlink($file_path);