Let's say I have this directory structure:
myApp
|____files
|
|__myFolder
| |___script1.php
|
|__script2.php
|___myClass.php
script1.php
and script2.php
are identical, and all they do is instantiate myClass, put a file in the files
folder, and print out an HTML anchor link to that file.
//script1.php and script2.php:
/*require myClass*/
$myClass = new myClass();
$myClass->copyFile();
$link = $myClass->retHref();
echo '<a href="'.$link.'">Click here</a>
Currently I am doing this in myClass.php, to get the absolute path and href:
//myClass.php
class myClass{
public function copyFile()
{
$absPath = dirname(__FILE__).'/files/file.txt';
//code to copy the file
}
public function retHref()
{
return $_SERVER['HTTP_REFERER'].'/files/file.txt';
}
}
Is this the best way to go about this, or is there a better way to
a) Get a file path
and
b) Create a web link
from inside a class, when I don't know where the script will live that instantiates the class and calls its functions?