Link to home
Start Free TrialLog in
Avatar of webseth
webseth

asked on

Fatal error: Call to undefined function zip_open()

Hi, I'm getting this error:
Fatal error: Call to undefined function zip_open() in /home/xxxxxx/public_html/cron_folder/data_cron.php on line 39.

Zlib support is enabled on the server. Php Ver. 5.2.2 Any ideas? Contacted my hosting company, and it was pointless. The same EXACT script works on THREE different sites hosted with the same packages by the same company. I don't know, maybe there's a problem with the script, maybe not. I just need to know where to go from here.

Thanks Again!


<?
     define ( 'LOG_FILE', 'log.txt' ); // log file that records the complete process
     define ( 'FTP_USER', 'xxxxxx' ); // ftp login username
     define ( 'FTP_PASS', 'xxxxxx' ); // ftp login password
     define ( 'FTP_HOST', 'xxxxxx.com' ); // ftp server name
     define ( 'SAVE_PATH', '/home/xxxxxx/public_html/cron_folder/' ); // inlude the trailing '/'


     $get_file = 'DailyData_CATisRES.zip'; // path and name of file on the FTP server (download file)
     $new_file = SAVE_PATH . 'DailyData_CATisRES.zip'; // the local temp zip file name and path... (save file)
     // end configure

  $files = array ();

     log_file ( 'SCRIPT (START): New database dump process started', 1 );

     $io = ftp_connect ( FTP_HOST ) or log_file ( 'FTP CONNECT: connection error, ' . FTP_HOST, 0 );

     log_file ( 'FTP (CONNECT): connection to ' . FTP_HOST . ' returned true', 1 );

     if ( ( $lu = @ftp_login ( $io, FTP_USER, FTP_PASS ) ) !== false )
     {
          log_file ( 'FTP (LOGIN): login to ' . FTP_HOST . ' returned true', 1 );

          $lf = fopen ( $new_file, 'wb' ) or log_file ( 'FILE ERROR: can not create temp file, ' . $new_file, 0 );

              ftp_pasv($io, true) or log_file ( 'FTP PASV: Unable to set passive mode.', 0 );

          if ( ftp_fget ( $io, $lf, $get_file, FTP_BINARY, 0 ) !== false )
          {
               log_file ( 'FTP (GET): get download file ' . $get_file . ' returned true', 1 );

               fclose ( $lf );

               log_file ( 'FILE (SAVE): saved down load file ' . $get_file . ' to ' . $new_file, 1 );

               
                     $zf = zip_open ( $new_file ) or log_file ( 'FILE ERROR: can not open to unzip, ' . $new_file, 0 );

               if ( $zf )
               {
                    while ( $zs = zip_read ( $zf ) )
                    {
                         if ( zip_entry_open ( $zf, $zs, 'rb' ) !== false )
                         {
                              $zo = zip_entry_read ( $zs, zip_entry_filesize ( $zs ) );
                              $fn = zip_entry_name ( $zs );

                              $fs = fopen ( SAVE_PATH . $fn, 'wb' );
                              fputs ( $fs, $zo );
                              fclose ( $fs );

                              $files[$fn] = SAVE_PATH . $fn;
                         }
                    }
                              
                    zip_close ( $zf );

                    log_file ( 'FILE (UNZIP): process download file, ' . $new_file . ' returned true', 1 );

                    unlink ( $new_file );

               }
               else
               {
                    log_file ( 'FILE ERROR: can not open or read ' . $new_file . ' (check permissions)', 0 );
               }

          }
          else
          {
               log_file ( 'FILE ERROR: can not download ' . $get_file . ' from ' . FTP_HOST . ' (check path)', 0 );
          }

          ftp_close ( $io );

     }
     else
     {
          log_file ( 'FTP ERROR: user not allowed access on ' . FTP_HOST, 0 );
     }

     log_file ( 'SCRIPT (END): New database dump process finished, exiting...', 2 );
       print "Scipt Seemed to Have Work";


     function log_file ( $data, $type )
     {
          $time = date ( 'r', time () );

          $fo = fopen ( LOG_FILE, 'a' );
          fputs ( $fo, $time . ', ' . $data . "\r\n" );

          if ( $type == 2 )
          {
               fputs ( $fo, str_repeat ( '-', 72 ) . "\r\n\r\n" );
          }

          fclose ( $fo );

          if ( $type == 1 )
          {
               return;
          }

          exit ();
     }

?>
Avatar of ljubiccica
ljubiccica
Flag of Slovenia image

What is in $zf ???

Because zip_open returns a number of error -> you should know what's the problem...

Greets
Ljubiccica
Avatar of Kiran Paul VJ
can u post a link to phpinfo
Avatar of webseth
webseth

ASKER

ASKER CERTIFIED SOLUTION
Avatar of Kiran Paul VJ
Kiran Paul VJ
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Write to log file what is in $zf...

You use $zf = zip_open ( $new_file ) or log_file ( 'FILE ERROR: can not open to unzip, ' . $new_file, 0 );

after that write:
log_file ( 'ZF CONNTENT: ".$zf );

What does it say?
@ ljubiccica,

$zf will have nothing in it. Because php cannot find the zip_open function, so it returns a fatal error and stops execution, so the next line log_file() wont work.

yes, i figured that out...

:/
some good info here by bisqwit at iki dot fi
http://au.php.net/manual/en/function.zip-open.php 

////
If your PHP installation does not have the zip_open function, and you can't install it for whatever reason, you can use these functions instead, if the server has access to the "unzip" utility (most Linux systems do).
So far I have tested these only in Fedora Core 3.
Use at your own risk.

<?php

function ShellFix($s)
{
  return "'".str_replace("'", "'\''", $s)."'";
}

function zip_open($s)
{
  $fp = @fopen($s, 'rb');
  if(!$fp) return false;
 
  $lines = Array();
  $cmd = 'unzip -v '.shellfix($s);
  exec($cmd, $lines);
 
  $contents = Array();
  $ok=false;
  foreach($lines as $line)
  {
    if($line[0]=='-') { $ok=!$ok; continue; }
    if(!$ok) continue;
   
    $length = (int)$line;
    $fn = trim(substr($line,58));
   
    $contents[] = Array('name' => $fn, 'length' => $length);
  }
 
  return
    Array('fp'       => $fp,
          'name'     => $s,
          'contents' => $contents,
          'pointer'  => -1);
}                          
function zip_read(&$fp)
{
  if(!$fp) return false;
 
  $next = $fp['pointer'] + 1;
  if($next >= count($fp['contents'])) return false;
 
  $fp['pointer'] = $next;
  return $fp['contents'][$next];
}
function zip_entry_name(&$res)
{
  if(!$res) return false;
  return $res['name'];
}                          
function zip_entry_filesize(&$res)
{
  if(!$res) return false;
  return $res['length'];
}
function zip_entry_open(&$fp, &$res)
{
  if(!$res) return false;

  $cmd = 'unzip -p '.shellfix($fp['name']).' '.shellfix($res['name']);
 
  $res['fp'] = popen($cmd, 'r');
  return !!$res['fp'];  
}
function zip_entry_read(&$res, $nbytes)
{
  return fread($res['fp'], $nbytes);
}
function zip_entry_close(&$res)
{
  fclose($res['fp']);
  unset($res['fp']);
}
function zip_close(&$fp)
{
  fclose($fp['fp']);
}
?>
///
Avatar of webseth

ASKER

Says Function does not exist...
Avatar of webseth

ASKER

Warning: popen() has been disabled for security reasons in /home/xxxxxx/public_html/cron_folder/data_cron.php on line 61
yep I saw ur pager.class file, can u try my last suggestion
Avatar of webseth

ASKER

the last warning was from your last suggestion.....looks like it's going to be a hosting company issue.....the same script works on another site hosted by the same company....so i used the function_exists idea that you gave.....function exists on other site, not on this one.....the host needs to rectify.
one of the strange thing i noticed is that the extension zlib is loaded but the zip_open function does not exits. It happens in my system also

<?php
if(function_exists("zip_open"))
{
    echo("Function exists");
}
else
{
   echo("Function does not exists");
}


if (extension_loaded('zlib'))
{
    echo("zlib loaded");
    }
      else
      echo("zlib NOT loaded");
?>