What are some common functions or methods in PHP that can be used to send files to the browser?
To send files to the browser in PHP, you can use functions like `readfile()`, `fopen()`, `fread()`, and `echo`. These functions allow you to open a file, read its contents, and send it directly to the browser for download or display.
$file = 'path/to/file.pdf';
// Set the appropriate headers for the file type
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="' . basename($file) . '"');
// Send the file to the browser
readfile($file);
Keywords
Related Questions
- What is the difference between using copy() and move_uploaded_file() functions in PHP for file handling?
- What potential pitfalls should developers be aware of when using functions like xtc_get_products_attribute_price in PHP?
- How can PHP be used to interact with a .htaccess file for authentication purposes in a forum setting?