Skip to content
This repository has been archived by the owner on Jul 8, 2023. It is now read-only.

Subdirectory/relative path extraction #39

Open
tomasfejfar opened this issue Mar 2, 2018 · 1 comment
Open

Subdirectory/relative path extraction #39

tomasfejfar opened this issue Mar 2, 2018 · 1 comment

Comments

@tomasfejfar
Copy link

Is it currently possible to do a "reverse resolving"? Get relative subdirectory path from base path and absolute path?

$basePath = '/var/www/';
$absolutePath = FileSystemPath::fromString('/var/www/project/public/index.php');
$relativePath = $absolutePath->getRelativePath($basePath);
// project/public/index.php
@ezzatron
Copy link
Contributor

ezzatron commented Mar 4, 2018

Yes, this is possible with relativeTo().

However, if you're translating HTTP request paths into paths on disk, please be aware of the various path traversal attacks that you might open yourself up to. You might want to look at Guzzle's UriResolver, to do some sanitation/validation before your request path even makes it into a file system path.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants