• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2596
  • Last Modified:

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 ();
     }

?>
0
webseth
Asked:
webseth
  • 6
  • 4
  • 3
1 Solution
 
ljubiccicaCommented:
What is in $zf ???

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

Greets
Ljubiccica
0
 
Kiran Paul VJComputer EngineerCommented:
can u post a link to phpinfo
0
 
websethAuthor Commented:
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Kiran Paul VJComputer EngineerCommented:
try this in a fresh new page

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

what is it echoing
0
 
ljubiccicaCommented:
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?
0
 
Kiran Paul VJComputer EngineerCommented:
@ 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.

0
 
ljubiccicaCommented:
yes, i figured that out...

:/
0
 
Kiran Paul VJComputer EngineerCommented:
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']);
}
?>
///
0
 
websethAuthor Commented:
Says Function does not exist...
0
 
websethAuthor Commented:
Warning: popen() has been disabled for security reasons in /home/xxxxxx/public_html/cron_folder/data_cron.php on line 61
0
 
Kiran Paul VJComputer EngineerCommented:
yep I saw ur pager.class file, can u try my last suggestion
0
 
websethAuthor Commented:
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.
0
 
Kiran Paul VJComputer EngineerCommented:
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");
?>
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now