Php: How to protect images for downloading [duplicate]

you can do this by using force download in php.

$file_url="base path to file / file name";
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary"); 
header("Content-disposition: attachment; filename=\"" . basename($file_url) . "\""); 
readfile($file_url);

this code will download the file and block files folder using htaccess

<IfModule authz_core_module>
   Require all denied
</IfModule>

<IfModule !authz_core_module>
   Deny from all
</IfModule>

Leave a Comment