John Davidson

Php how to go one level down on dirname(__FILE__)?


with this code I get filename from the current folder

$mydir = dirname(__FILE__);
$myfiles = array_diff(scandir($mydir), array('.', '..'));
$arrsingleresult = str_replace('.php', '', $myfiles);

Now how can I get filenames from one folder back ? (../ like this) any work around ?

My Answer:
To go one level down from the current directory using `dirname(__FILE__)`, you can use the `dirname()` function twice. Here is an example:

$currentDirectory = dirname(__FILE__);
$parentDirectory = dirname($currentDirectory);

echo $parentDirectory;

This code will give you the path to the parent directory of the current file. You can continue to use `dirname()` multiple times to go further up the directory structure if needed.

Rate this post

3 of 5 based on 7795 votes


© 2024 - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us