Jump to content


Photo

Call to a member function add_file() on a non-object


  • Please log in to reply
No replies to this topic

#1 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 02 September 2006 - 04:59 PM

This maybe a rather simple one to fix but I am not seeing were I am going wrong. I am getting the following error Fatal error: Call to a member function add_file() on a non-object in zip.php on line 21

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

<?php
require('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();
?>

Here is the add_file function
	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;
	}

Any suggestions as to what I am doing wrong?

Thanks,
Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users