How can PHP be adapted to handle file downloads that are not in PDF format?
To handle file downloads that are not in PDF format in PHP, you can use the header() function to specify the content type of the file being downloaded. This will ensure that the browser knows how to handle the file being sent from the server.
<?php
$file = 'example.jpg';
header('Content-Type: image/jpeg');
header('Content-Disposition: attachment; filename="' . basename($file) . '"');
readfile($file);
exit;
?>
Keywords
Related Questions
- What are the best practices for handling database query results and resource variables in PHP to avoid unintended behavior like premature loop termination?
- What are the common pitfalls when trying to include SVG images in PDF prints using PHP?
- How can PHP be used to upload files to a different server using FTP?