您可以使用数组表示法获取完整文件路径的一部分,例如
echo $path_parts['dirname'], "\n";
echo $path_parts['basename'], "\n";
echo $path_parts['extension'], "\n";
echo $path_parts['filename'], "\n"; // since PHP 5.2.0
但除了“basename”被错误命名(因为它返回整个文件名)之外,“basename”和“filename”版本只返回文件名的第一个字符。如果文件名是Archive.zip并且我执行以下操作:
echo "Here's the zip filename: " . $zipFilename . "<br>";
echo "Here's the basename: " . $zipFilename['basename'] . "<br>";
echo "Here's the 'filename': " . $zipFilename['filename'];
我得到:
Here's the zip filename: Archive.zip
Here's the basename: A
Here's the 'filename': A
如果我在完整路径uploads/Archive.zip上尝试它,我会得到:
Here's the zip filename: uploads/Archive.zip
Here's the basename: u
Here's the 'filename': u
知道为什么吗?谢谢。