You need the server's PATH_INFO variable for this to work correctly. But be aware that you need to configure your server accordingly as well.
Then in PHP you can call pathinfo() like this:
<?php
$path_parts = pathinfo('/www/htdocs/inc/lib.inc.php');
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
?>
Server configuration for
Apache
# Set document root to be "webroot"
DocumentRoot "path/to/webroot"
<Directory "path/to/webroot">
# use mod_rewrite for pretty URL support
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
# ...other settings...
</Directory>
and Nginx:
server {
# ...
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
#fastcgi_pass unix:/var/run/php5-fpm.sock;
try_files $uri =404;
}
# ...
}
WARNING: this can pose several security issues if not configured properly, make sure that:
- User upload files can never be accessed when this rule is applied
- set
["cgi.fix_pathinfo = 0;" in php.ini][2]
../../path/to/cssFile.cssuse/path/to/cssFile.css