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?

  • 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. – usernameabc Nov 22 '17 at 17:19
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

-1

first of all you must create a private fille in filles filles/private then create another private fille not in public_html but in home : /home/private

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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