php实现带权限的文件图片下载

有时候我们需要做下载文件,通常是使用类似 PHP readfile函数将文件输出到浏览器,再通过设置mini 类型来实现下载,这样做会有效率问题和网络大量网络IO,那么使用 X-Accel-Redirect 就可以避免这个问题具体配置如下:

nginx配置

location /protected_files {
  internal;
  proxy_pass https://127.0.0.8/file/; #使用代理
}

#或者
location /protected_files {
  internal;
  root  /var/www/file;
}

//发送本地文件
header("X-Accel-Redirect:/protected_files/10.mp4");
//发送远程文件 最终会转发到https://127.0.0.8/file/file?path=xxx.mp4
header("X-Accel-Redirect:/protected_files/file?path=xxx.mp4");


图片压缩guetzli

发表新评论