Zipping in php script not working

Status
Not open for further replies.

pballz

New Member
Messages
24
Reaction score
0
Points
1
I tried to run my backup script and got the following error.

Code:
[B]Fatal error[/B]:  Class 'ZipArchive' not found in [B]/home/......../zip.php[/B] on line [B]21[/B]
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.
 

Skizzerz

Contributors
Staff member
Contributors
Messages
2,928
Reaction score
118
Points
63
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.
 

pballz

New Member
Messages
24
Reaction score
0
Points
1
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.
 

Skizzerz

Contributors
Staff member
Contributors
Messages
2,928
Reaction score
118
Points
63
The zip extension is not enabled because it uses a large amount of CPU, which can cause High Resource Usage suspensions.
 

pballz

New Member
Messages
24
Reaction score
0
Points
1
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?
 
Status
Not open for further replies.
Top