I am trying to catch (echo) a file or directory from a certain directory.
I want to bind it to a variable.
No i am experiencing with realpath and he gives me the exact file location but from the server.
echo realpath($dir.'/'.$file);
So my echo shows me this: /home/vhosts/mydomain.com/subdomains/develop3/httpdocs/uploads/sfm/c4ca4238a0b923820dcc509a6f75849b/Jellyfish.jpg
or /home/vhosts/mydomain.com/subdomains/develop3/httpdocs/uploads/sfm/c4ca4238a0b923820dcc509a6f75849b/nameofdirectory
it should be this:
uploads/sfm/c4ca4238a0b923820dcc509a6f75849b/Jellyfish.jpg
and uploads/sfm/c4ca4238a0b923820dcc509a6f75849b/nameofdirectory
How can i achieve that?
I'm not sure of what you really need and what is the value of $dir
, but you can use:
$fullPath = realpath($dir.'/'.$file);
$relativePath = preg_replace('%/home.*httpdocs/%i', '', $fullPath);