

Before you try these out, create a new PHP page and save it as fileDir.php. This is useful for finding the exact location (relative or absolute) of your scripts or pages.
#PHP GET FILE PATH OF CURRENT FILE FULL#
If you would like to get the full url, you can do something like:Įcho $_SERVER. There are a few inbuilt PHP functions you can use to find out file paths. $_SERVER – gives the correct HTTP(S) protocol and domain name.
$_SERVER – gives the route of the current file (after the domain name) You create a new File instance by passing in the path to the file in the. There is also a function to parse URLs built in to PHP:

The directory the script is located in on the servers filesystem, and the URL, are 2 completely different things. That gives you the location on the filesystem/server (not the URL) that your script is running from. Please note that echo getcwd() is not what you want, based on your question. In the case above that will give you /~andy (without test.php at the end). If you want the directory your current script is running in – without the filename – use: Adapt this accordingly for your environment, replacing the 5.6 or number with the actual version folder that exists on your environment.For example if the URL is The output would be: You can then upload the file to the directory where you want to place the.
#PHP GET FILE PATH OF CURRENT FILE CODE#
Copy the code and paste it into a file called fullpath.php. Below is a small PHP script that prints the full path to the directory it is placed in. SERVER'PHPSELF' - gives the route of the current file (after the domain name) /this/is/a/url SERVER'SERVERNAME' - gives the domain name SERVER'HTTPREFERER' - gives the correct HTTP(S) protocol and domain name.

etc/php/5.6/fpm/php.ini is for the php5-fpm processor, which is a fastcgi-compatible 'wrapper' for PHP processing (such as to hand off from NGINX to php5-fpm) and runs as a standalone process on the system (unlike the Apache PHP plugin)įor versions of Ubuntu lower than 16.04, /etc/php/5.6/, /etc/php/7.0/, /etc/php/7.1/, and so on, are replaced by /etc/php5/ and so on. If you dont know the full path and PHP is installed on the server, you can get some help here. This is the one you need to edit for changes to be applied for your Apache setup which utilizes the in-built PHP module to Apache. etc/php/5.6/apache2/php.ini is for the PHP plugin used by Apache. etc/php/5.6/cgi/php.ini is for the php-cgi system which isn't specifically used in this setup. etc/php/5.6/cli/php.ini is for the CLI PHP program, which you found by running php on the terminal. The three files you have there are each meant for different uses. Is there any chance there could be another php.ini file that could be interfering? The resulting path might significantly differs from the input even when absolute path is given. It does not work on a path as a string, but also resolves symlinks. I tried rebooting my computer thinking maybe that would stop the apache server and reload the php.ini file with the correct setting, but alas that attempt also failed. realpath () is just a system/library call to actual realpath () function supported by OS. Which was supposed to be changed to 20M but was still only 2M I know this because I used echo ini_get('post_max_size') I reloaded the page and it showed that the php.ini file was not updated. I restarted apache using sudo service apache2 restart I changed all of them (just to be sure) to the settings I wanted. Loaded Configuration File => /etc/php5/cli/php.ini SERVER 'QUERYSTRING' The query string, if any, via which the page was accessed. If PHP is running as a command-line processor this variable contains the script name since PHP 4.3.0. $ sudo php -i | grep 'Configuration File'Ĭonfiguration File (php.ini) Path => /etc/php5/cli The FILE constant contains the full path and filename of the current (i.e. This is how I found the files $ sudo find / -name php.ini It will use memory mapping techniques if supported. filegetcontents () is the preferred way to read the contents of a file into a string. PHP Date and Time PHP Include PHP File Handling PHP File Open/Read PHP File Create/Write PHP File.

On failure, filegetcontents () will return false. I have found three different php.ini files (no idea why there are three) This function is similar to file (), except that filegetcontents () returns the file in a string, starting at the specified offset up to length bytes. I am currently trying to locate the correct php.ini file to edit it and restart apache so the changes will take place and I'm stumped.
