要在非Web访问目录中的文件的URL(Readfile()?Fopen()?...) [英] URL to file in non web accessible directory (Readfile()? Fopen()?...)
问题描述
$ destination = $ _SERVER [DOCUMENT_ROOT]。 /../Uploads/。 $随机的;
mkdir($ destination);
move_uploaded_file($ temp,$ destination。/。$ name);
$ final = $ server。/。$ destination。/。$ name;
** $ yourfile = readfile('$ final'); **
然后我回覆我们的$ yourfile:
<?php echo $ yourfile; ?>
其他地方。
没有打开流,还是一个巨大的长串。是否有任何解决方案可以通过URL请求下载文件?
编辑:我想保持目录不可访问。
readfile
直接输出内容,不返回。或者阅读file_get_contents上的手册页。
readfile('$ final');
永远不会成功。除非文件具有 $ final
的名称。双引号或无引号。
您的问题已经回答了几百次。没有必要连续四次发布你的问题。
- PHP在web服务器根目录之外显示/下载目录文件
- 如何使用PHP从Web根外部提供文档?
- 使用PHP从外部Web根文件夹中显示所有图像
- https://stackoverflow.com/search?q=php%20readfile%20from%20outside%20docroot
so files are uploaded to a non web accessible directory on my server, but i want to provide a URL or some for of download access to these files. Below is my attempt, but it isn't working.
$destination = $_SERVER["DOCUMENT_ROOT"] . "/../Uploads/" . $random;
mkdir($destination);
move_uploaded_file($temp, $destination."/".$name);
$final = $server."/".$destination."/".$name;
**$yourfile = readfile('$final');**
and i then echo our $yourfile:
<?php echo $yourfile; ?>
elsewhere.
I either get a failed to open stream, or a huge long string. Is there any solution to just download the file on request via URL?
EDIT: I want to keep the directory non web accessible.
readfile
outputs the content directly, it does not return it. Alternatively read the manual page on file_get_contents.
readfile('$final');
is never going to succeed. Unless the file literally had the "$final
" name. Double quotes or no quotes.
Your question has been answered a few hundred times already. There's no need for you to post your issue four times in a row.
- PHP display/download directory files outside the webserver root
- How to serve documents from outside the web root using PHP?
- Display all images from outside web root folder using PHP
- https://stackoverflow.com/search?q=php%20readfile%20from%20outside%20docroot
这篇关于要在非Web访问目录中的文件的URL(Readfile()?Fopen()?...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!