John Davidson

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

0 comments
Message:


with this code I get filename from the current folder


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

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:

php
$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

5 of 5 based on 9975 votes

Comments




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