andre1990
andre1990

Reputation: 107

URL to file in non web accessible directory (Readfile()? Fopen()?...)

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.

Upvotes: 1

Views: 1539

Answers (1)

mario
mario

Reputation: 145482

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.

Upvotes: 2

Related Questions