Hi I'm trying to create a zip and adding some pdf files into it but getting error when i try to check if the folder exists or not i don't know where I'm doing mistake please tell me if my code is right or wrong . Here is my code .
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);
        }
    }
}
Please have a look at this i think this is a simple condition check but i don't know where i'm mistaken My question is not duplicate cause i'm getting an error message that says file is not in the folder here is the error Warning: ZipArchive::close(): Failure to create temporary file: No such file or directory in /home/ameliadeol2015/public_html/wp-content/plugins/lifterlms/includes/admin/reporting/tables/llms.table.student.courses.php on line 137
 
    