принудительно загружать изображения с помощью htaccess


Я хочу принудительно загрузить изображение вместо открытия в браузере. Я попробовал использовать следующий код с php

//set the content as octet-stream     
header("Content-Type: application/octet-stream");    // 
// tell the thing the filesize 
header("Content-Length: " . filesize($download_path.$file));     
// set it as an attachment and give a file name 
header('Content-Disposition: attachment; filename='.$file); 
// read into the buffer 
readfile($download_path.$file);
Author: Cœur, 2014-08-27

1 answers

Добавьте нижеприведенную строку в .htaccess

<FilesMatch "\.(?i:jpg|gif|png)$">
  Header set Content-Disposition attachment
</FilesMatch>
 3
Author: Udhayakumar, 2014-08-27 06:08:42