ratcateme Posted June 28, 2008 Share Posted June 28, 2008 I have two files /var/www/html/phpeasycaptcha/Main.class.php and /var/www/html/pec.php and i want to find the path between them so that pec.php can link to Main.class.php Scott. Link to comment https://forums.phpfreaks.com/topic/112304-find-the-path-to-another-file/ Share on other sites More sharing options...
phpzone Posted June 28, 2008 Share Posted June 28, 2008 <?php require_once dirname(__FILE__) . '/phpeasycaptcha/Main.class.php'; ?> Link to comment https://forums.phpfreaks.com/topic/112304-find-the-path-to-another-file/#findComment-576596 Share on other sites More sharing options...
ratcateme Posted June 28, 2008 Author Share Posted June 28, 2008 i want a method to do it from the /var/www/html/phpeasycaptcha/Main.class.php file and also i want it to work no matter what dir the files are in. Scott. Link to comment https://forums.phpfreaks.com/topic/112304-find-the-path-to-another-file/#findComment-576605 Share on other sites More sharing options...
phpzone Posted June 28, 2008 Share Posted June 28, 2008 Then in Main.class.php you want to include pec.php? Ok... if your other file is always one directory up then the following.... <?php require_once dirname(dirname(__FILE__)) . '/pec.php'; ?> If it's anywhere on the system, I'm not 100% sure but you could use passthru and search with a system command: <?php $basepath = '/var/www/html'; $result = passthru("find {$basepath} -name 'pec.php' -print"); echo $result; ?> Link to comment https://forums.phpfreaks.com/topic/112304-find-the-path-to-another-file/#findComment-576606 Share on other sites More sharing options...
ratcateme Posted June 28, 2008 Author Share Posted June 28, 2008 no what happens is pec.php includes Main.class.php inside Main.class.php i can get the location of the url called by $_SERVER["SCRIPT_FILENAME"] and i can get the location of Main.class.php by __FILE__ so that will return /var/www/html/pec.php for $_SERVER["SCRIPT_FILENAME"] and /var/www/html/phpeasycaptcha/Main.class.php for __FILE__ what i want is to find the path to the /var/www/html/phpeasycaptcha/ dir from pec.php without any hard code so the dir could change to something like this /var/www/html/random/phpeasycaptcha/ and would still work without having to change the code Link to comment https://forums.phpfreaks.com/topic/112304-find-the-path-to-another-file/#findComment-576608 Share on other sites More sharing options...
phpzone Posted June 28, 2008 Share Posted June 28, 2008 I updated my last post, perhaps a system search will help. <?php $basepath = '/var/www/html'; $result = passthru("find {$basepath} -name 'Main.class.php' -print"); echo $result; ?> Link to comment https://forums.phpfreaks.com/topic/112304-find-the-path-to-another-file/#findComment-576609 Share on other sites More sharing options...
ratcateme Posted June 28, 2008 Author Share Posted June 28, 2008 hmm yea not really what i want as there could be a lot of files to search through i don't know if this is a very good thing to do i think i might look for another way but thanks for the help Scott. Link to comment https://forums.phpfreaks.com/topic/112304-find-the-path-to-another-file/#findComment-576613 Share on other sites More sharing options...
phpzone Posted June 28, 2008 Share Posted June 28, 2008 No probs, maybe someone else can help. Why do you need to do this btw., I would be interested in why there is a need? Link to comment https://forums.phpfreaks.com/topic/112304-find-the-path-to-another-file/#findComment-576615 Share on other sites More sharing options...
ratcateme Posted June 28, 2008 Author Share Posted June 28, 2008 i am creating a class to create captcha's (words with lines through them that are hard to read) and i have 2 files one with the main class to output the html code. in that there will be an <img> tag linking it to display.php that will output a jpeg image with the word and fuzzy lines. i want to do this so i can tell it where to find display.php to load the image Scott. Link to comment https://forums.phpfreaks.com/topic/112304-find-the-path-to-another-file/#findComment-576621 Share on other sites More sharing options...
phpzone Posted June 28, 2008 Share Posted June 28, 2008 Ok. I don't see the reason for having to 'find' things. I've done this and usually on my sites I have a structure like: /images/ /classes/ /templates/ header.php index.php config.php footer.php My can you not have a standard structure, keep your image.php in /images/ and your class in a folder? Then have a variable in config.php that defines your BASE_PATH and use that? Link to comment https://forums.phpfreaks.com/topic/112304-find-the-path-to-another-file/#findComment-576629 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.