Jump to content

find the path to another file


ratcateme

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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