Jump to content

How to print upper folder PHP


inversesoft123

Recommended Posts

Hello can anyone tell me how to print upper folder in PHP from the file which is located in sub folder..

 

eg: public_html / mysite / music / new / index.php

 

$home =  'http://mysite.com/';
$current_folder = basename(dirname(__FILE__));
echo '<a href="'.$home.'">Home</a> / <a href="'.$home.$current_folder.'">'.$current_folder.'</a><br/>';  

 

In this code I can link to currennt folder 'new' but how do I link 'music' folder in this script..

 

Pls Help... Tnx n advance

Link to comment
https://forums.phpfreaks.com/topic/147423-how-to-print-upper-folder-php/
Share on other sites

Well the music folder does not need to be exactly right under the home folder. Also note that server path and web path might be and most of the times are different. So using something like dirname(__FILE__) is not the best idea when you want to use it as an URL.

 

However linking to parent directory could be usually done via ".." :). So when the current directory is /home/test/new and I want to link to a file inside that "test" I can write /home/test/new/../file.php. This works for both server path and web path.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.