PHP:更改调用脚本的环境

时间:2013-11-20 10:52:34

标签: javascript php html image directory

这是我的问题,我有一个PHP脚本调用javascript脚本启动ckeditor,这是一个带有预定义html内容的富文本编辑器:

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

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

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

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";
}

?>

问题是在我的html文件中,我使用相对路径调用一些图像,如

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

图片文件夹位于我的$ ref文件夹中。图像不会充电,因为脚本未在良好目录中启动。我想强制剧本知道他改变了他的路径,所以他可以在正确的地方取得图像。我徒劳地试过chdir。如果我将我的图像文件夹放在与我的PHP脚本相同的级别上它可以工作,但我不能这样做(这个脚本的目的是在一个大型数据库中,树枝不能改变,副本会太重了)。 有人有解决这个问题的方法吗?我很难解释这一点,所以如果还不是很清楚,你可以提出一些问题以获取更多信息。

1 个答案:

答案 0 :(得分:1)

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

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