Technically, pathinfo
is correct: the one and only extension for that file is .gz
. The fact that it has .tar
in the name is as coincidental as the fact that it has 5.0.1
in it.
That doesn't make your interest in checking for .tar.gz
files invalid, but it does raise the question: what specifically do you want to find?
The most direct solution to your specific question is: first look for the extension (via pathinfo
or the strpos function) and then if it happens to be .gz
look for the "extension" in the remaining filename (via the same technique).
$parts = pathinfo($filename);
$extension = $parts['extension'];
if ($extension == '.gz') {
$parts = pathinfo($parts['filename']);
$extension = $parts['extension'] . $extension;
}