PHP 获取错误条件无法正常工作



嗨,我正在尝试创建一个zip并在其中添加一些pdf文件,但是当我尝试检查该文件夹是否存在时出现错误,我不知道我在哪里做错了请告诉我我的代码是对还是错。 这是我的代码.

public function createZips(){
if (is_dir("/home/servername/public_html/wp-content/pdf_files/".$stdname)){
if(!(file_exists("/home/servername/public_html/wp-content/pdf_files/".$stdname."/zip/".$ct[-1].".zip"))){
$zip = new ZipArchive();
$filename = "/home/servername/public_html/wp-content/pdf_files/".$stdname."/zip/".$ct[-1].".zip";
if ($zip->open($filename, ZipArchive::CREATE)!==TRUE) {
exit("cannot open <$filename>n");
}
$dir = "/home/servername/public_html/wp-content/pdf_files/".$stdname."/".$ct[-1];
// Create zip
$this->createZip($zip,$dir);
$zip->close();
}
return ture;
}
return false;
}
// Create zip
public function createZip($zip,$dir){
if (is_dir($dir)){
if ($dh = opendir($dir)){
while (($file = readdir($dh)) !== false){
// If file
if (is_file($dir.$file)) {
if($file != '' && $file != '.' && $file != '..'){
$zip->addFile($dir.$file);
}
}else{
// If directory
if(is_dir($dir.$file) ){
if($file != '' && $file != '.' && $file != '..'){
// Add empty directory
$zip->addEmptyDir($dir.$file);
$folder = $dir.$file.'/';
// Read data of the folder
$this->createZip($zip,$folder);
}
}
}
}
closedir($dh);
}
}
}

请看一下这个,我认为这是一个简单的状况检查,但我不知道我错在哪里 我的问题没有重复,因为我收到一条错误消息,说文件不在文件夹中,这是错误 警告:ZipArchive::close((:无法创建临时文件:在/home/ameliadeol2015/public_html/wp-content/plugins/lifterlms/include/admin/reporting/tables/llms.table.student.courses.php 第 137 行中没有这样的文件或目录

您似乎没有定义$ct,因此当您尝试访问$ct[-1]时,它不会有值。

最新更新