What are the implications of using absolute file paths versus relative file paths in PHP for downloading files?

When downloading files in PHP, using absolute file paths can make the code less portable and may cause issues when moving the code to a different server or directory structure. Relative file paths, on the other hand, are more flexible and can adapt to different environments. It is recommended to use relative file paths when downloading files in PHP to ensure better portability and maintainability of the code.

// Using relative file path to download a file
$file = 'downloads/example.pdf';
header('Content-Description: File Transfer');
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename=' . basename($file));
header('Content-Length: ' . filesize($file));
readfile($file);
exit;