How can meta tags be used to initiate automatic downloads in PHP?
Meta tags can be used to initiate automatic downloads in PHP by setting the content-disposition header to "attachment" and specifying the filename in the "filename" parameter. This will prompt the browser to download the file instead of displaying it.
<?php
$file = "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;
?>
Related Questions
- How can PHP developers troubleshoot issues related to missing CSS, JS, and image files in a website hosted on a PLESK server?
- How can the use of global variables impact the functionality of PHP classes and their interactions?
- What are the key security measures to prevent session fixation, XSS, and CSRF attacks in PHP web applications?