PHP:更改调用脚本的环境

PHP : Change environment where the script is called

本文关键字:脚本 环境 调用 PHP      更新时间:2023-09-26

这是我的问题,我有一个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,但没有成功。如果我把我的images文件夹放在与php脚本相同的级别上,它就可以工作,但我不能这样做(这个脚本的目的是在一个大型数据库中,在这个数据库中,树状场景无法更改,副本会太重)。有人能解决这个问题吗?我很难解释这一点,所以如果还不太清楚,你可以问一些问题以获得更多信息。

    //~ 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";