?WEB服务器设置禁止此路径的访问(httpd: Deny from all, nginx: return 403)然后PHP脚本中用file_get_contents()读入该路径中的文件直接输出,并设置header的Content-Type为该资源对应的MIME类型(不知道就application/octet-stream)。
httpd。config:<Directory "E:/wwwroot/download/bak"> Deny from all </Directory>php 文件存在E:/wwwroot/download download。php :<?php $fileres = file_get_contents("http://localhost/download/bak/logo.jpg"); echo $fileres; ?>上传按找刚才的办法,已经可以了,但是下载的时候会提示 Warning: file_get_contents(http://localhost/download/bak/logo.jpg) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in E:\wwwroot\download\download.php on line 2就差这个问题了,希望能解决,辛苦各位
如果是windows,就给那个目录增加Guests的读、写和删除权限。
设置 access deny 或者 使用 http 认证 或者 重定向
上传和下载通过另外的php文件进行的,和上面做的没有影响
跟这个操作没有关系。
上传文件是PHP在服务端进行的读写操作,与WEB服务器的访问设置无关。
Deny from all
</Directory>php 文件存在E:/wwwroot/download
download。php :<?php
$fileres = file_get_contents("http://localhost/download/bak/logo.jpg");
echo $fileres;
?>上传按找刚才的办法,已经可以了,但是下载的时候会提示
Warning: file_get_contents(http://localhost/download/bak/logo.jpg) [function.file-get-contents]: failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in E:\wwwroot\download\download.php on line 2就差这个问题了,希望能解决,辛苦各位