Domanda

Is it possible to get the path to the php.ini file with a php script and save this path to a variable? I know I can call phpinfo() to find out the path, but it prints a lot of info and I only need the path to php.ini file and no output at all. Thank you in advance.

È stato utile?

Soluzione

Sure, there are two functions related to what you would like to do. The first one is exactly what you're looking for, the second one shows the bigger picture that there can be more than one ini file:

  1. php_ini_loaded_fileDocs - Retrieve a path to the loaded php.ini file.
  2. php_ini_scanned_filesDocs - Return a list of .ini files parsed from the additional ini dir.

Next to that, mind the gap with .user.ini files, they don't show up in php_ini_scanned_files nor phpinfo.

Altri suggerimenti

You could exec("php -i | grep php.ini"), and grab that output. Or you could use outputbuffering (ob_start()), run phpinfo(), get the contents of the outputbuffer (ob_get_contents()) and search trough that (preg_match) to find the php.ini file...

This works on the command line, might also work for the CGI:

ob_start(); phpinfo();
if ( preg_match( '#>(.+)/php.ini#', ob_get_clean(), $matches ) ) {
    echo 'php.ini location: ' . trim( $matches[1] ) . '/php.ini';
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top