JavaScript — я хочу скачать файлы, когда я нажимаю на имя изображения или имя файла в переполнении стека

$path = "https://surv-translation.com/assets/uploads/files/";
$filename = "1544615073screenshot-trustwortha.com-2018.11.29-16-37-46.png";
header('Content-Transfer-Encoding: binary');  // For Gecko browsers mainly
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($path)) . ' GMT');
header('Accept-Ranges: bytes');  // For download resume
header('Content-Length: ' . filesize($path));  // File size
header('Content-Encoding: none');
header('Content-Type: application/pdf');  // Change this mime type if the file is not PDF
header('Content-Disposition: attachment; filename=' . $filename);  // Make the browser display the Save As dialog
readfile($path);
exit;

Я пробовал использовать этот код, но я не добился успеха, и я хочу загрузить любой файл, такой как docx, pdf, ppt или image и т. Д., Так что вы можете мне помочь, пожалуйста?

-2

Решение

Вы можете попробовать этот код для загрузки любого файла, как доктор, PDF, п.п. или же образ, так далее

if (file_exists($filepath)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . basename($filepath) . '"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($filepath));
flush(); // Flush system output buffer
readfile($filepath);
exit;
}
1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector