Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 340
  • Last Modified:

I have tried everything - php unzip

I am trying to get this old code to work and for some reason It is no longer working. I have tried to figure out so maybe someone can give me a hand.

Here is the error
Fatal error: Call to undefined function: zip_open() in /home/bored/public_html/sadunzip.php on line 32


here is the code I am using to unzip
<?php


/*


=========================================================================================


      sadunzip


      Written by Jacob Vivian (jacob (at) sadsoft (odt) com)


      


      ============


      Author notes (JV):


      I got tired of seeing different undocumented and unreliable methods I found on PHP.net


      covering the different things you can do to manipulate the zip technology, and found useful


      just writing my own using some of the basics documented and my own php knowledge.  Enjoy.


      


      ============


      Usage:


      sadunzip("place/where/zips/are/located", "extractedarea/", "file.zip");


      


      Just to note:  If running in root, just put "" (EX -- sadunzip("", "extractedarea/", "file.zip"); -- )


      Also: If you want to have no extract directory put (EX -- sadunzip("place/where/zips/are/located", "", "file.zip"); -- )


      


      ============


      Revision:


      0.1a -- sadunzip was born.  Lot's to do such as testing all the different OS' with this.


=========================================================================================


*/





function sadunzip($absolutepath, $extractdir, $file)


{


      // Set Path


      $path = getcwd().$absolutepath;


      //echo $path.$file;


      //Zip open


      $zip = zip_open($path."/".$file);


      


      if($zip)


      {


            while ($zip_entry = zip_read($zip))


            {


                  //echo "Name:              " . zip_entry_name($zip_entry) . "\n<br >";


                  //echo "Actual Filesize:    " . zip_entry_filesize($zip_entry) . "\n<br >";


                  //echo "Compressed Size:    " . zip_entry_compressedsize($zip_entry) . "\n <br >";


                  //echo "Compression Method: " . zip_entry_compressionmethod($zip_entry) . "\n<br >";


                  if (zip_entry_open($zip, $zip_entry, "r"))


                  {


                        // Extract in directory or not?


                        if($extractdir)


                        {


                              if(is_dir($path."/".$extractdir))


                              {


                                    // Read contents file by file into buffer


                                    $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));


                                    if(!file_exists($path."/".$extractdir."/".zip_entry_name($zip_entry)))


                                    {


                                          $fp = fopen($path."/".$extractdir."/".zip_entry_name($zip_entry), "w");


                                          fwrite($fp, $buf);


                                          zip_entry_close($zip_entry);


                                    }


                              }


                              else


                              {


                                    mkdir($path."/".$extractdir);


                                    chmod($path."/".$extractdir, 0777);


                                    // Read contents file by file into buffer


                                    $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));


                                    if(!file_exists($path."/".$extractdir."/".zip_entry_name($zip_entry)))


                                    {


                                          $fp = fopen($path."/".$extractdir."/".zip_entry_name($zip_entry), "w");


                                          fwrite($fp, $buf);


                                          zip_entry_close($zip_entry);


                                    }


                              }


                        }


                        else


                        {


                              // Read contents file by file into buffer


                              $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));


                              if(!file_exists($path."/".$extractdir."/".zip_entry_name($zip_entry)))


                              {


                                    $fp = fopen($path."/".$extractdir."/".zip_entry_name($zip_entry), "w");


                                    fwrite($fp, $buf);


                                    zip_entry_close($zip_entry);


                              }


                        }


                  }


            }


      }


      else


      {


            die("sadunzip: Unable to locate/utilize supplied zip file.");


      }


}


?>
0
lamerhooDJV
Asked:
lamerhooDJV
  • 2
1 Solution
 
david_levineCommented:
The error indicates PHP doesn't know what to do with the zip_open command. zip_open is not a base part of PHP. See http://us2.php.net/manual/en/ref.zip.php

Is this a server you have control over or some shared web hosting provider? Do you manage the server? Seems something has changed in the environment not necessarily with your PHP application code.
0
 
lamerhooDJVAuthor Commented:
Getting that installed now
will post back
0
 
lamerhooDJVAuthor Commented:
Sorry for the delayed response and grade.  It worked great! :)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now