Question

I have a variable $path which contains the full path to a file on a Windows network (e.g. R:\somedir\otherdir\lastdir\some.file.ext)

when I use:

    $location = dirname($path);

here, $location only records the value .

What am I doing wrong?

Was it helpful?

Solution

You are using the wrong slash. Instead of using the backslash \ use the normal slash /

A file path and a URI are different. \ is correct in a Windows file path and / is correct in a URI.

So this file path: C:\Documents\Foo translates to this URI: file:///C:/Documents/Foo

From the php documentation:

If there are no slashes in path, a dot ('.') is returned, indicating the current directory. Otherwise, the returned string is path with any trailing /component removed.

This means that the problem is that your slashes are wrong.

http://php.net/manual/en/function.dirname.php

OTHER TIPS

Replace \ with / and try again

Consider using a forwardslash '/'.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top