Jack Maessen Jack Maessen - 6 months ago 10
PHP Question

Eliminating last part of url string in php

I have a url string like this:

http://example.com/sfm?dir=uploads/sfm/root/folder5/file.zip


echo $_GET['extract']
outputs this:
uploads/sfm/root/folder5/file.zip

How can i strip the last file.zip so that

echo $_GET['extract']
outputs this:
uploads/sfm/root/folder5/

Answer

Just use dirname - Returns a parent directory's path

echo dirname($_GET['extract'])."/";
Comments