我无法通过使用变量
来读取路径$absPath = realpath('./');
//$absPath = /home/abc/domains/server2.abc.com/public_html/mockup
//$oldPath = /project_image/easy/Desert.jpg
$npath = $absPath."".$oldPath; //$oldPath is get by image element scr="xxx"
$ npath将返回此信息:
/home/abc/domains/server2.abc.com/public_html/mockup/project_image/easy/Desert.jpg
当我取消链接时
unlink($npath);
然后php返回
No such file or directory in /home/../mockup/update_file.php -> point unlink($npath);
我尝试硬编码
$npath = /home/abc/domains/server2.abc.com/public_html/mockup/project_image/easy/Desert.jpg
unlink($npath);
然后它会成功。
我想知道如何使用变量组合新路径来取消链接。
抱歉我的英语不好
答案 0 :(得分:-1)
您确定您的脚本生成完全相同的路径吗?如果正在构建路径并且取消链接失败,则可以尝试使用shell。有时这与samba坐骑和什么不一样。
$absPath = realpath('./');
$npath = $absPath."".$oldPath;
// Bail if the path doesn't exist
if(!file_exists($npath)) die('Failed to build correct path');
// Try unlink via PHP
if(!unlink($npath) || file_exists($npath)) {
// PHP couldn't cut it, try unlink via shell
exec('rm ' . $npath, $output, $return);
if($return > 0)
die('Failed to delete file: ' . $npath);
}