Php:如何保护下载的图像



在我的网站上,我们正在做图像保护部分。我可以在不下载的情况下保护我的网站中的图像不受他人影响吗。那就是我想保护我的图像不被其他人下载。是否可以使用php代码

您可以通过在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);

该代码将使用htaccess 下载文件和阻止文件文件夹

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

最新更新