Smarty,没有生成php编译文件 unlink

unlink(E:/server/www/myphp\tmp\templates_c\%�^87E^87EFA86F%�mo.hello.phtml.php) [function.unlink]: No such file or directory

查看templdtes_c文件夹,没有找到对应的编译文件,只有wrt33C.tmp文件,而且刷新一次就产生一个,大致就是没有生成php编译文件(或是生成了,但名称不对),于是在unlink的时候找不到。文件夹权限和smarty配置都没有问题。

解决办法:

找到smarty文件夹里面internals文件夹下面的core.write_file.php文件,大致在44行,原来是:

 if (DIRECTORY_SEPARATOR == '\\' || !@rename($_tmp_file, $params['filename'])) {
    // On platforms and filesystems that cannot overwrite with rename()
    // delete the file before renaming it -- because windows always suffers
    // this, it is short-circuited to avoid the initial rename() attempt
     @unlink($params['filename']);
     @rename($_tmp_file, $params['filename']);
}

改成:

if (DIRECTORY_SEPARATOR == '\\' || !@rename($_tmp_file, $params['filename'])) {
    // On platforms and filesystems that cannot overwrite with rename()
    // delete the file before renaming it -- because windows always suffers
    // this, it is short-circuited to avoid the initial rename() attempt
    if(file_exists($params['filename'])) {
        @unlink($params['filename']);
    }
    @rename($_tmp_file, $params['filename']);
}

就是加一个判断。问题解决了,但暂时还是不明白为什么会出现这个问题,之前用smarty都是好好的。

smarty虽然不错,但最近用php直接写模板,发现还是相当舒服,而且省去了编译的一步。

猜你喜欢

转载自blog.csdn.net/qq_41281571/article/details/82118929