我的模型中有以下函数:
public function createfolder($location, $name){
define('NET_SFTP_LOGGING', NET_SFTP_LOG_COMPLEX);
$sftp = new Net_SFTP('xx.xxx.xx.xx');
if (!$sftp->login('admin', '********')) {
exit('Login Failed');
}
//moves to a location (Job folder for example)
$sftp->chdir($location);
//makes the folder
$sftp->mkdir($name);
}
这可行,但我想添加某种错误预防验证,我如何使用 SFTP 检查文件夹是否存在?
想出一个解决方案:
chdir()
changes directories,mkdir()
creates directories, andrmdir()
removes directories. In the event of failure, they all returnfalse
.chdir()
,mkdir()
, andrmdir()
returntrue
on successful completion of the operation.
所以我可以使用 if
语句来检查 if chdir() === true
或 false
以查看目录是否存在.
最佳答案
您可以使用 $sftp->is_dir($location)
来检查它是否是一个目录。
https://stackoverflow.com/questions/22502016/