

So you can edit the php.ini file indicated in the Loaded Configuration File section, and that should work in most cases. And the second one, Loaded Configuration File, is the path from where the php.ini file is being loaded when PHP is run. The first one, Configuration File (php.ini) Path, indicates the default path of the php.ini file in your system. Look for the following section.Īs you can see, there are two sections. Load this file in your browser, and you should see the output of phpinfo(). Go ahead and create the phpinfo.php file with the following contents and place it in your document root: It will tell you where php.ini is located, and it will also output all the important PHP configuration information. This is where the phpinfo() function comes to the rescue. On the other hand, if you’re running another operating system, then it’s difficult to guess the exact location of the php.ini file-there are several possibilities. If you’re running Windows, you'll likely find the php.ini file within the directory of your PHP installation in the system drive. This can be tricky-the location of the php.ini file vastly varies by the environment you’re running PHP with.
#Get file path in php how to#
In this section, we’ll see how to find the php.ini file which is loaded when you run the PHP script. In fact, as a PHP developer, it’s inevitable, and you’ll encounter it sooner rather than later. However, the php.ini file provides a couple of important settings that you want to make yourself familiar with. In fact, there are no critical configuration parameters that you must set in order to run PHP. PHP can run happily with the settings provided in the default php.ini file, since PHP ships with these default recommended settings. On the other hand, it’s certainly possible that you've never needed to modify php.ini. Quite often, you’ll find you need to tweak settings in the php.ini file. This file allows you to configure a few important settings that you should be aware of. When PHP is run, it looks for the php.ini file in some specific locations and loads it. Whether you’re a PHP beginner or a seasoned developer, I’m sure that you’ve heard of php.ini: the most important PHP configuration file. From the beginner’s perspective, we’ll discuss what it’s meant for, where to locate it, and a couple of important configuration settings it provides. echo basename(dirname(_FILE_)).In this tutorial, we’re going to discuss php.ini-the main configuration file in PHP.

For example, if the path provided is /var/In this way, we can get the current working directory name in PHP. The basename() function returns the name of the base file or folder from the given path. We can apply this function with the result of the above two functions. We can use the basename() function to get the current working directory name without the path in PHP.

Use the basename() Function to Get the Current Directory Name in PHP In this way, we can get the current working directory name in PHP. echo _FILE_ įor example, write the dirname() function in the index.php file with the _FILE_ constant as the parameter. For example, we get the following result when we echo the _FILE_ constant from the index.php file. We can demonstrate these constants and the function in the above directory structure.
#Get file path in php full#
The _FILE_ constant returns the full path of the current file along with the file name. Levels indicate the number of directories to move up.įinally, we can use the _FILE_ magic constants in the dirname() function to get the name of the current directory. It accepts two parameters where the first one is the path and the second one is levels. The function returns the path of the parent directory. We can also use the dirname() function to get the current directory name in PHP. Use the dirname() Function to Get the Current Directory Name in PHP We can see in the output section that the getcwd() function returns the current working directory with its path. We can use the echo function to display the content of the function. The getcwd() function will return the name of the current working directory, which is project. The PHP file lies inside the project directory. Let’s consider the following directory structure. The function returns false in case of failure. The function does not take any parameters. The returned value is a string on success. The getcwd() function gives the current working directory. Use the getcwd() Function to Get the Current Directory Name in PHP This article will introduce a few methods to get the current working directory name in PHP. Use the basename() Function to Get the Current Directory Name in PHP.Use the dirname() Function to Get the Current Directory Name in PHP.Use the getcwd() Function to Get the Current Directory Name in PHP.
