PHP:更改调用脚本的环境

Here's my problem, I have a php script who calls a javascript script which launches ckeditor, a rich text editor with a predefined html content :

<?PHP
$ref = $_GET['req'];

//~ Launches ckeditor
$h = "<html><head><script src='ckeditor/ckeditor.js'></script>
";
$h =$h."<link href='sample.css' rel='stylesheet'>
";
$h =$h."<style>
";
$h =$h.".cke_textarea_inline 
";
$h =$h."{
";
$h =$h."padding: 10px;
";
$h =$h."height: 500px;
";
$h =$h."overflow: auto;
";
$h =$h."border: 1px solid gray;
";
$h =$h."-webkit-appearance: textfield;
";
$h =$h."}
";
$h =$h."</style></head><body>
";
$h = $h."<div style='position:absolute; left:50px; top:120px; width:1200px; height:600px;'>
" ;
$h =$h."<form action='posteddata.php' method='post'>
";
$h =$h."<textarea name='article-body' style='height:600px'>
";

//~ Add a submit button which is irrelevant to my problem
$f = "</textarea><p><input type='submit' value='Submit'></p></form>
";
$f = $f."<script>CKEDITOR.inline( 'article-body' );</script>
";
$f = $f."</body></html>
";

chdir($ref);

if(file_exists("System Specification.html"))
{
    $file = fopen("System Specification.html", "r");
    print $h;
    while (!feof($file))
    {
        print fgets($file,4096);
    }
    print $f;
}
else 
{
    echo "Cannot open file";
}

?>

The problem is that in my html file, I call some images with a relative path like

<img src='images/2/1.gif' />

The images folder being in my $ref folder. The images don't charge because the script is not launched in the good directory. I'd like to force the script to know he changed his path, so he can fetch for the images in the right place. I tried chdir in vain. If I put my images folder on the same level as my php script it works but I can't do that this way (the purpose of this script is to be in a large database where the arborescence can't be changed and the copy would be too heavy). Does someone have a solution to this problem ? I struggle to explain this, so if it's still not very clear you can ask some questions for further information.

    //~ Launches ckeditor
        $h = "<html><head><script src='ckeditor/ckeditor.js'></script>
";
        $h.= "<link href='sample.css' rel='stylesheet'>
";
        $h.= "<style>
";
        $h.= ".cke_textarea_inline 
";
        $h.= "{
";
        $h.= "padding: 10px;
";
        $h.= "height: 500px;
";
        $h.= "overflow: auto;
";
        $h.= "border: 1px solid gray;
";
        $h.= "-webkit-appearance: textfield;
";
        $h.= "}
";
        $h.= "</style></head><body>
";
        $h.= "<div style='position:absolute; left:50px; top:120px; width:1200px; height:600px;'>
" ;
        $h.= "<form action='posteddata.php' method='post'>
";
        $h.= "<textarea name='article-body' style='height:600px'>
";

//~ Add a submit button which is irrelevant to my problem
$f = "</textarea><p><input type='submit' value='Submit'></p></form>
";
$f = $f."<script>CKEDITOR.inline( 'article-body' );</script>
";
$f = $f."</body></html>
";