URL to file in non web accessible directory (Readf

2019-08-12 07:12发布

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.

1条回答
我欲成王,谁敢阻挡
2楼-- · 2019-08-12 07:23

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.

查看更多
登录 后发表回答