How to get access outside HTDOCS with PHP script

553 views Asked by At

I have a webserver with Apache.

For security reasons my customer wants to access files (.jpg/.pdf/.png/.gif) in another folder.

The root layout is as follows:

  • backup
  • data
  • etc
  • htdocs
  • logs
  • tmp

In the htdocs folder the Joomla website resides. I use flexicode to add PHP code to the site.

Is there a way I can show for example a photo in .jpg from the data folder? example. /data/werknemers/80111/pasfoto.jpg

There is a little snag. Everybody uses a pin number to log into Joomla. In this case pin 80111. Pin 80111 is added to the users table, the field is called pin.

Is it possible to use a variable to retrieve the data? So only user 80111 can access his or her folder and not another one?

The photo is shown in a module on the website after login.

Cheers,

Steve

2

There are 2 answers

6
veelen On

You'll have to write a php script in joomla (for the authorisation), and give apache access to the external folder. Then deliver your files using this script.

1
casivaagustin On

I'm not a Joomla user, but my first chance will be to look for some plugin to manage the uploads, I saw some plugins to manage uploads per user doing a quick google search, for example this one.

In the case that no one works for you I think the next option will be try to implement an asset proxy.

  • Write an script in htdocs to validate the PIN and if it is ok read the file content from the data directory and provide the output from that script.

  • An rewrite rule to redirect all .jpg/.pdf/.png/.gif request for that proxy will be need.

  • Be aware to serve the non secure content (theme images for example) as well.

Hope this help