1

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.

andre1990
  • 107
  • 2
  • 9
  • @mario Thanks for your reply mario, so what do you suggest i use instead? – andre1990 Oct 23 '11 at 11:30
  • possible duplicate of [How to URL Link to file outside root directory](http://stackoverflow.com/questions/7862307/how-to-url-link-to-file-outside-root-directory) – mario Oct 23 '11 at 11:33

1 Answers1

2

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.

Community
  • 1
  • 1
mario
  • 144,265
  • 20
  • 237
  • 291