What are best practices for setting permissions and expiration times for downloadable files in PHP?

When dealing with downloadable files in PHP, it is important to set appropriate permissions to ensure that only authorized users can access the files. Additionally, setting expiration times for the download links can help prevent unauthorized access to the files after a certain period.

// Set permissions for the downloadable file
chmod("path/to/downloadable/file", 0644);

// Set expiration time for the download link (e.g. 1 hour)
$expiration_time = time() + 3600;

// Generate a unique download link with expiration time
$download_link = "http://example.com/download.php?file=file_name&expires=$expiration_time";

// Redirect user to the download link
header("Location: $download_link");