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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.