Closed Thread
Results 1 to 6 of 6

Thread: Zipping in php script not working

  1. #1
    pballz is offline x10Hosting Member pballz is an unknown quantity at this point
    Join Date
    Aug 2009
    Posts
    24

    Zipping in php script not working

    I tried to run my backup script and got the following error.

    Code:
    Fatal error:  Class 'ZipArchive' not found in /home/......../zip.php on line 21
    I'm guessing the update of php has something to do with this but the newer version shouldn't have broken it.

    Posting script in case that helps

    Code:
    //how to call zip function
    include 'zip.php';
    zip('/home/pballz/public_html');
    
    //zip.php contents
    <?php
    function recurse_zip($src,&$zip,$path_length) {
        $dir = opendir($src);
        while(false !== ( $file = readdir($dir)) ) {
            if (( $file != '.' ) && ( $file != '..' )) {
                if ( is_dir($src . '/' . $file) ) {
                    recurse_zip($src . '/' . $file,$zip,$path_length);
                }
                else {
                    $zip->addFile($src . '/' . $file,substr($src . '/' . $file,$path_length));
                }
            }
        }
        closedir($dir);
    }
    //Call this function with argument = absolute path of file or directory name.
    function zip($src)
    {
        global $zip_fname;
        $zip_fname='backup_'.date("Y-m-d_H-i-s").'.zip';
        $zip = new ZipArchive;
        $res = $zip->open($zip_fname, ZipArchive::CREATE);
        if($res !== TRUE){
            echo 'Error: Unable to create zip file';
            exit;
        }
        if(is_file($src)){$zip->addFile($src,substr($src,$path_length));}
        else{
            if(!is_dir($src)){
                $zip->close();
                @unlink($zip_fname);
                echo 'Error: File not found';
                exit;
            }
            recurse_zip($src,$zip,$path_length);
        }
        $zip->close();
    }
    ?>
    I did not make this.

  2. #2
    Skizzerz's Avatar
    Skizzerz is offline Contributors Skizzerz will become famous soon enough
    Join Date
    Nov 2007
    Location
    Texas
    Posts
    2,153

    Re: Zipping in php script not working

    Hello,

    The zip extension is not enabled on the Free Hosting servers. Try using the PharData class to create the .zip, which is supported. Please note that if you have a large number of files to compress (or large file sizes), you may run into a High Resource Usage suspensions. If this is the case, it is recommended that you try these instructions to back up your site.
    Ryan Schmidt | Level 2 Support
    █ 888-X10-9668 - ryan[@]x10hosting.com
    x10Hosting - Giving Away Hosting Since 2004
    Premium Hosting | VPS Services

  3. #3
    pballz is offline x10Hosting Member pballz is an unknown quantity at this point
    Join Date
    Aug 2009
    Posts
    24

    Re: Zipping in php script not working

    Why was zipping disabled?

  4. #4
    pballz is offline x10Hosting Member pballz is an unknown quantity at this point
    Join Date
    Aug 2009
    Posts
    24

    Re: Zipping in php script not working

    Just wondering if anyone can answer my last question and if anyone knows where to find a working example using that phar thing to zip a directory.

  5. #5
    Skizzerz's Avatar
    Skizzerz is offline Contributors Skizzerz will become famous soon enough
    Join Date
    Nov 2007
    Location
    Texas
    Posts
    2,153

    Re: Zipping in php script not working

    The zip extension is not enabled because it uses a large amount of CPU, which can cause High Resource Usage suspensions.
    Ryan Schmidt | Level 2 Support
    █ 888-X10-9668 - ryan[@]x10hosting.com
    x10Hosting - Giving Away Hosting Since 2004
    Premium Hosting | VPS Services

  6. #6
    pballz is offline x10Hosting Member pballz is an unknown quantity at this point
    Join Date
    Aug 2009
    Posts
    24

    Re: Zipping in php script not working

    I don't want to argue too much, but you can still zip stuff via the cpanel. Which on my old site setup was constantly suspending me. So what is the difference between letting people do it via cpanel and in a php script?

Closed Thread

Similar Threads

  1. Problem zipping files via cpanel
    By pball in forum Free Hosting
    Replies: 3
    Last Post: 05-22-2011, 03:22 PM
  2. Replies: 4
    Last Post: 09-27-2010, 04:37 PM
  3. My Script is not working.
    By janmck in forum Free Hosting
    Replies: 1
    Last Post: 03-18-2010, 09:30 AM
  4. Ads script not working
    By bzerby in forum Free Hosting
    Replies: 2
    Last Post: 01-23-2008, 05:04 PM
  5. CGI script not working
    By unpixelatedgamers in forum Free Hosting
    Replies: 5
    Last Post: 03-14-2006, 07:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers