Jump to content

Echo/List previous folder?


yakking

Recommended Posts

I found a php code that will echo/list the current folder that the file is in:

 

 

<?php

foreach(glob('directoryname/*', GLOB_ONLYDIR) as $dir) {
    $dir = str_replace('directory/', '', $dir);
    echo $dir;
}
; ?>
 

 

Is it possible to have the same thing except echo/list the previous folder that the file is in?

 

Thanks for any help!

Link to comment
Share on other sites

Hi Barand

 

Sorry I should have expanded on what I was asking.

That above code is in a php file, if you request that php file in a browser it prints/echos the current folder that the php file is in. e.g. /directoy/name/

 

So what I am asking is there a way to print/echo the folder/directory that the /directory/name/ folder is in I can't think of the terminology, I think its called parent directory. e.g. /folder<--/name/ so the php file is in the /name/ folder I would like to print the /folder/ part. Now heres the catch, the /folder/ can actually be named anything, hence why I need the code to echo/print it, it's not static.

 

Thanks for any help you can provide!

Link to comment
Share on other sites

Thanks Ch0cu3r!

That's so close to what I am after! With those examples it returns all the folder paths e.g /home/public_html/folder_here/another_folder

So if I use basename can I get just the /folder_here/  and not the whole /home/public_html/folder_here/another_folder path?
I had a look at the basename examples in the link, is there an example that I would understand?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.