不可通过 Web 访问的目录中文件的 URL(Readfile()?Fopen()?...)
所以文件被上传到我的服务器上的不可通过网络访问的目录,但我想提供一个 URL 或一些对这些文件的下载访问权限。以下是我的尝试,但它不起作用。
$destination = $_SERVER["DOCUMENT_ROOT"] . "/../Uploads/" . $random;
mkdir($destination);
move_uploaded_file($temp, $destination."/".$name);
$final = $server."/".$destination."/".$name;
**$yourfile = readfile('$final');**
然后我
<?php echo $yourfile; ?>
在其他地方回显我们的 $yourfile: 。
我要么打开流失败,要么得到一个巨大的长字符串。有什么解决方案可以通过 URL 根据请求下载文件吗?
编辑:我想保持该目录不可通过网络访问。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
readfile
直接输出内容,不返回内容。或者阅读 file_get_contents 上的手册页。readfile('$final');
永远不会成功。除非文件确实具有“$final
”名称。双引号或不带引号。你的问题已经被回答了几百次了。您无需连续发布四次问题。
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.