Accessing linked files in the parent folder of webroot (public_html)

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
davebryan
Posts: 13
Joined: 2015-11-06 16:19

Accessing linked files in the parent folder of webroot (public_html)

Post by davebryan » 2016-09-23 15:07

I have a bunch of PDF files stored in a subfolder (pdf_stor) of public_html and access them with an Appgini field configured as a link. When entering the link address, I prepend "/pdf_stor/" to the PDF file name and that works well. What I want to do is move the PDF folder to the parent of the public_html folder (I'll call it server root) so the PDFs cannot be accessed by a user unless it is by the link. I have created a folder in server root and stored the PDF files there, but cannot access them with the link button. Link.php always defaults to starting in webroot and I cannot get it to use the correct path to the folder in the server root. Do I have to modify link.php or what is the correct path I should prepend to the file name?

Appreciate any help.

grimblefritz
AppGini Super Hero
AppGini Super Hero
Posts: 336
Joined: 2015-12-23 16:52

Re: Accessing linked files in the parent folder of webroot (public_html)

Post by grimblefritz » 2016-09-23 22:29

A URL cannot back up beyond the web (document) root, in your case public_html. You cannot create a link that will directly reference the files if you place them above the root.

What you need is a PHP download script. You pass the script an ID of the file to download - which can be stored pretty much anywhere - and the script handles the details of dumping the file to the browser. You see this a lot with download sites, where your link is actually a reference ID of some kind and not the actual file.

A quick google found this: http://www.zubrag.com/scripts/download.php

And many other examples.

Good luck!

davebryan
Posts: 13
Joined: 2015-11-06 16:19

Re: Accessing linked files in the parent folder of webroot (public_html)

Post by davebryan » 2016-09-26 15:03

Thanks for the feedback. I realized that the only access to the web root's parent directory (server root) was with a php script. My assumption was that link.php does that, since the Appgini link button calls link.php and passes the necessary information to it. By default, it is only set up to access the web root using dirname(__FILE__). In order to get to the server root, I need to either define a path to the server root in link.php or prepend the path to the server root to the file name entered in the link field. Unfortunately, everything I have tried so far doesn't work and my php programming skills are still pretty limited.

Noha Eshra
Moderator
Posts: 82
Joined: 2013-11-11 19:21

Re: Accessing linked files in the parent folder of webroot (public_html)

Post by Noha Eshra » 2016-09-28 12:09

Indeed you cannot link to a file outside the document root (public_html in your case). Link.php file cannot be used in this case either. An alternative solution, if all you want to do is preventing users from accessing the pdf links directly, is to prevent "hot linking" using an htaccess file inside the pdf folder (and you can now safely keep that folder inside public_html).

For details, please check this link: http://www.cyberciti.biz/faq/apache-mod ... ing-howto/

Post Reply