PHP File Download
Learn how to download files using PHP safely and effectively.
PHP का उपयोग करके सुरक्षित रूप से फाइल डाउनलोड करना सीखें।
Basic File Download
This example will trigger a file download from the server.
यह उदाहरण सर्वर से फाइल डाउनलोड को ट्रिगर करेगा।
<?php
$file = 'downloads/sample.pdf'; // Path to file
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . basename($file) . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;
} else {
echo "File not found.";
}
?>