tomfmason Posted September 2, 2006 Share Posted September 2, 2006 This maybe a rather simple one to fix but I am not seeing were I am going wrong. I am getting the following error [b]Fatal error: Call to a member function add_file() on a non-object in zip.php on line 21[/b]The zip.php is rather simple. Basicly what it does it goes through a loop and searches the current directory and then adds the sub directorys and all files to a zip file. Here is the zip.php[code]<?phprequire('includes/class.php');clearstatcache();$zip_dir ="./". $_SERVER['HTTP_HOST'] ."." . date("Ymd") . ".zip";if (is_dir($zip_dir) == false) { mkdir($zip_dir);}$folders = array();$zipfile = new zipFile();$zipfile -> add_dir($zip_dir);$path = "./";if ($dirc = opendir($path)) { $d = 0; while (($file = readdir($dirc)) !== false) { if ($file != '.' && $file != '..') { if (is_dir($path . $file)) { $d++; $folders[$d] = $path . $file; $zipfile -> add_dir($zip_dir . "/" . $file); }else{ $zip_file -> add_file($file, $zip_dir);//this is line 21 } } }}closedir($dir);function get_sub_folders($folders) { $d = count($folders); foreach ($folders as $folder) { if ($dirc = opendir($folder)) { while ($file = readdir($dirc)) { $pathto = $folder . "/" . $file; if ($file != '.' && $file != '..' && !in_array($folders)) { if (is_dir($file) == true) { $d++; $folders[$d] = $pathto; $zipfile -> add_dir($zip_dir . "/" . $pathto); }else{ $dir = $zipfile $zipfile -> add_file($file, $zip_dir . "/" . $pathto); } $folders = get_sub_folders($folders); } } } closedir($folders); } sort($folders); return $folders;}$getfolders = get_sub_folders($folders);$zfile = zfile();?>[/code]Here is the add_file function [code=php:0] function add_file($file, $dir) { $name = str_replace("\\", "/", $dir); $unc_len = strlen($file); $crc = crc32($file); $zdata = gzcompress($file); $zdata = substr($zdata, 2, -4); $c_len = ($zdata); $fr = "\x50\x4b\x03\x04"; $fr .= "\x14\x00"; $fr .= "\x00\x00"; $fr .= "\x08\x00"; $fr .= "\x00\x00\x00\x00"; $fr .= pack("V", $crc); $fr .= pack("V", $c_len); $fr .= pack("V", $unc_len); $fr .= pack("v", $dir); $fr .= pack("v", 0); $fr .= $dir; $fr .= $zdata; $fr .= pack("V", $crc); $fr .= pack("V", $c_len); $fr .= pack("V", $unc_len); $this -> datasec[] = $fr; $new_offset = strlen(implode("", $this->datasec)); $cdrec = "\x50\x4b\x01\x02"; $cdrec .= "\x00\x00"; $cdrec .= "\x14\x00"; $cdrec .= "\x00\x00"; $cdrec .= "\x08\x00"; $cdrec .= "\x00\x00\x00\x00"; $cdrec .= pack("V", $crc); $cdrec .= pack("V", $c_len); $cdrec .= pack("V", $unc_len); $cdrec .= pack("v", strlen($dir)); $cdrec .= pack("v", 0); $cdrec .= pack("v", 0); $cdrec .= pack("v", 0); $cdrec .= pack("v", 0); $cdrec .= pack("V", 32); $cdrec .= pack("V", $this-> old_offset); $this-> old_offset = $new_offset; $cdrec .= $dir; $this -> cltr_dir[] = $cdrec; }[/code]Any suggestions as to what I am doing wrong? Thanks,Tom Link to comment https://forums.phpfreaks.com/topic/19487-call-to-a-member-function-add_file-on-a-non-object/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.