Jump to content

Resolve relative path outside document root


haku

Recommended Posts

I need to find a way to resolve a relative path outside the document root, in a cross-platform friendly manner.

 

My users have a settings page where they are able to set the path to a folder where files should be included. This path may not exist at the time of saving the setting. The given path is then retrieved from the database when files are  being saved, the path is checked to see if a folder needs to be created, and the file is saved to the path.

 

Two possible paths they may use are:

* files (This is the webpath: http://site.com/files or absolute path /home/user/public_html/files)

* ../files (This is the absolute path: /home/user/files where the webroot is /home/user/public_html/)

 

The first path is easy to deal with. However, I'm having a rough time resolving the second path into a usable system path (i.e. /home/user/files). This needs to be cross platform compatible (windows/'Nix). I've played around with realpath(), but I'm just not finding something that works for me. Any suggestions?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.