要在非Web访问目录中的文件的URL(Readfile()?Fopen()?...) [英] URL to file in non web accessible directory (Readfile()? Fopen()?...)

查看:160
本文介绍了要在非Web访问目录中的文件的URL(Readfile()?Fopen()?...)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以文件被上传到我的服务器上的一个非Web访问目录,但我想提供一个URL或一些下载访问这些文件。以下是我的尝试,但它不起作用。

  $ 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 的名称。双引号或无引号。



您的问题已经回答了几百次。没有必要连续四次发布你的问题。




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.

这篇关于要在非Web访问目录中的文件的URL(Readfile()?Fopen()?...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆