0

I have a Drupal site at http://example.org/xyz

Per the instructions here, I have set up a private file directory outside the web root.

So let's say the web root is at /home/public_html/example/xyz The private directory is at /home/public_html/private

I have that private directory set in the settings.php file and cleared the caches. It shows up correctly here: http://example.org/xyz/admin/config/media/file-system

After clearing the cache, I can indeed confirm there is a valid .htaccess file in /atrium/admin/config/media/file-system

The directory permissions for the private directory are 755.

So now I specify the file location of a link in a block as "/xyz/system/myfile.pdf"

When I click the link, the home page simply reloads (instead of a download window), but the URL now reads: http://example.org/atrium/system/myfile.pdf

I've tried many other variations, and they all fail.

What am I doing wrong?

1
  • 1
    Couldn't you just use the public folder to provide links in a block? Private folders typically are used for when users upload forms containing sensitive information that only the site owners should see. Either way, have you tried Private Files Download block? This allows you to set permissions by role, which I am assuming is for anonymous users. Nov 22, 2017 at 17:19

1 Answer 1

0

drupal will not let you specify a direct link to a private file

If you upload the file using file field (core) then you can use views to display the file in a block using block display and use https://www.drupal.org/project/private_files_download_permission for fine grained permissions on who can download the file

if you want to program this behaviour then you have to look at using file_create_url in a custom module

$fid = 1; //set fid to your file's fid.
$downloadlink = file_create_url(file_load($fid)->uri);

and this link will hide the actual path where you private file is

for more details you can look at

How can I get the URL to the public files directory?

https://api.drupal.org/api/drupal/core%21includes%21file.inc/function/file_create_url/8.2.x

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.