Skip to main content
Inspiring
October 20, 2009
Answered

getting url path from known absolute path

  • October 20, 2009
  • 1 reply
  • 654 views

Is there a CF 8 function that will give me the url path for an a known OS absolute path.

For example if I have a path to a file or directory like:

C:\Inetpub\wwwroot\ccradius\public\applications\cruzcontrol\uploads\uploadpics\badday1.jpg

OR

C:\Inetpub\wwwroot\ccradius\public\applications\cruzcontrol\uploads\uploadpics\

Thanks for any help!!!

    This topic has been closed for replies.
    Correct answer Adam Cameron.

    No, there's no such function.  It's a bit tricky to automate because a directory on the file system could be mapped in any number of ways on the CF server, and there's no automatic way for CF to second-guess which mapping you'd want to be using.

    Basically what you need to do is to use expandPath() to expand a mapping that you want to use to resolve the file system path into a URL, and then look for a match of that in the path you are trying to convert.  If it's there, chop the file system path accordingly (and flip the slashes around if needs must).

    EG:

    Your path:

    C:\Inetpub\wwwroot\ccradius\public\applications\cruzcontrol\uploads\uploadpics\b adday1.jpg

    Your root mapping:

    / => C:\Inetpub\wwwroot\ccradius\

    So expandPath("/") resolves to C:\Inetpub\wwwroot\ccradius\

    Now use replace() to get rid of that bit of the path from your target path:

    public\applications\cruzcontrol\uploads\uploadpics\b adday1.jpg

    Prepend the mapping (which is just "/" in this case):

    /public\applications\cruzcontrol\uploads\uploadpics\b adday1.jpg

    Use replace() to substitute the \ with /

    /public/applications/cruzcontrol/uploads/uploadpics/b adday1.jpg

    --

    Adam

    1 reply

    Adam Cameron.Correct answer
    Inspiring
    October 22, 2009

    No, there's no such function.  It's a bit tricky to automate because a directory on the file system could be mapped in any number of ways on the CF server, and there's no automatic way for CF to second-guess which mapping you'd want to be using.

    Basically what you need to do is to use expandPath() to expand a mapping that you want to use to resolve the file system path into a URL, and then look for a match of that in the path you are trying to convert.  If it's there, chop the file system path accordingly (and flip the slashes around if needs must).

    EG:

    Your path:

    C:\Inetpub\wwwroot\ccradius\public\applications\cruzcontrol\uploads\uploadpics\b adday1.jpg

    Your root mapping:

    / => C:\Inetpub\wwwroot\ccradius\

    So expandPath("/") resolves to C:\Inetpub\wwwroot\ccradius\

    Now use replace() to get rid of that bit of the path from your target path:

    public\applications\cruzcontrol\uploads\uploadpics\b adday1.jpg

    Prepend the mapping (which is just "/" in this case):

    /public\applications\cruzcontrol\uploads\uploadpics\b adday1.jpg

    Use replace() to substitute the \ with /

    /public/applications/cruzcontrol/uploads/uploadpics/b adday1.jpg

    --

    Adam

    Inspiring
    October 23, 2009

    Thanks for the help!!

    Carlos