Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Senior Coder
    Join Date
    May 2006
    Posts
    1,680
    Thanks
    28
    Thanked 4 Times in 4 Posts

    A problem with ZipArchive

    Hi,

    So far, last Friday, every file file I try and open and unzip with
    the ZipArchive class has failed.

    I have just used ZipArchive to create a zip file and then
    attempt to unzip it.

    Even this has failed.

    Does this means that my server ZipArchive class is somehow corrupted ?

    Should I reinstall that php class ( I think it is via PECL )

    Or is there another reason ?

    here is my script for creating the zip file
    and then unzipping it.

    ( Because I am trying to trap every error it is longer than usual )

    PHP Code:
    $new_zip $file_dir.'aaa_new.zip';

    if (!
    class_exists('ZipArchive')) {
       
    write_log("Class ZipArchive not found\r\n"); 
       exit;
         } 
    else {
      
    write_log("Class ZipArchive OK\r\n"); 
      
    $zip = new ZipArchive;
    }

    $res $zip->open($new_zipZipArchive::CREATE);
    if (
    $res === TRUE) {
        
    $zip->addFromString('data1.txt''file content goes here');
        
    $fin $zip->close();
            if (
    $fin === TRUE) {
           
    write_log("Created zip file: $new_zip\r\n");
           } 
        else {
           
    write_log("Error on close: $fin \r\n");
               exit;  
               }   
        }
    else {
        
    write_log("Could NOT Create zip file $res\r\n");  
    }


    if (!
    $new_zip) {
        
    write_log("Could not find  $new_zip\r\n");  
        exit;
            } 
    else {
        
    write_log("Found: $new_zip\r\n");
        }

    $zip = new ZipArchive;
            
    $res $zip->open($new_zip);
    if (
    $res === TRUE) {
      
    write_log("File $new_zip OPENED\r\n");
        }
    else {
        
    write_log("Could not open $new_zip\r\n Error # $res\r\n");
        exit;
        }

    if (
    $zip->extractTo($file_dir) === TRUE) {
      
    write_log("Extracted: $new_zip\r\n");
      
    $zip->close();
        } 
    else {
      
    write_log("Extraction error\r\n");
      }

    $zipSS $zip->getStatusString();        
    write_log("StatusString: $zipSS\r\n");
      

    $fin $zip->close();
    if (
    $fin === TRUE) {
      
    write_log("Unzipped file to: $file_dir\r\n");
      } 
    else {
      
    write_log("Error on close: $fin \r\n");
        exit;  
        } 
    exit; 
    And YES the file "aaa_new.zip" does get created on
    my server.

    This is the log output:

    Class ZipArchive OK
    Created zip file: /home/gudfrt/public_html/stres/aaa_new.zip
    Found: /home/gudfrt/public_html/stres/aaa_new.zip
    File /home/gudfrt/public_html/stres/aaa_new.zip OPENED
    Extracted: /home/gudfrt/public_html/stres/aaa_new.zip
    StatusString:
    Error on close:

    Any ideas ?
    Last edited by jeddi; 03-01-2010 at 07:45 PM.
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •