src/Compress.php
public function archiveSingle($file, $desination = false)
    {
        if ($file == '') {
            throw new CompressException('__exception_compress_file_value_empty');
        }
        
        if (! file_exists($file)) {
            throw new CompressException('__exception_compress_file_not_exist');
        }
        
        if (! is_readable($file)) {
            throw new CompressException('__exception_compress_file_not_readable');
        }
        
        // work out path stuff
        $old_cwd = getcwd();
        $path = dirname($file);
        chdir($path);
        
        $name = $this->getArchiveName();
        $zip = $this->getArchiver();
        $zip->open($name, \ZipArchive::CREATE);
        if (file_exists($file)) {
            $zip->addFile(basename($file));
        }
        
        if ($zip->status != '0') {
            throw new CompressException('__exception_compression');
        }
        
        $zip->close();
        
        if (! $this->getKeepOriginal() && file_exists($file)) {
            unlink($file);
        }
        
        if ($desination) {
            $desination = realpath($desination) . DIRECTORY_SEPARATOR . $name;
            copy($name, $desination);
            unlink($name);
            
            $name = $desination;
        } else {
            $name = $path . DIRECTORY_SEPARATOR . $name;
        }
        
        // reset path
        chdir($old_cwd);
        
        return $name;
    }
public function archiveSingle($file, $desination = false)
    {
        if ($file == '') {
            throw new CompressException('__exception_compress_file_value_empty');
        }
        
        if (! file_exists($file)) {
            throw new CompressException('__exception_compress_file_not_exist');
        }
        
        if (! is_readable($file)) {
            throw new CompressException('__exception_compress_file_not_readable');
        }
        
        // work out path stuff
        $old_cwd = getcwd();
        $path = dirname($file);
        chdir($path);
        
        $name = $this->getArchiveName();
        $zip = $this->getArchiver();
        $zip->open($name, \ZipArchive::CREATE);
        if (file_exists($file)) {
            $zip->addFile(basename($file));
        }
        
        if ($zip->status != '0') {
            throw new CompressException('__exception_compression');
        }
        
        $zip->close();
        
        if (! $this->getKeepOriginal() && file_exists($file)) {
            unlink($file);
        }
        
        if ($desination) {
            $desination = realpath($desination) . DIRECTORY_SEPARATOR . $name;
            copy($name, $desination);
            unlink($name);
            
            $name = $desination;
        } else {
            $name = $path . DIRECTORY_SEPARATOR . $name;
        }
        
        // reset path
        chdir($old_cwd);
        
        return $name;
    }
public function archiveSingle ( $ file , $ desination = false ) { if ( $ file == '' ) { throw new CompressException ( '__exception_compress_file_value_empty' ) ; } if ( ! file_exists ( $ file ) ) { throw new CompressException ( '__exception_compress_file_not_exist' ) ; } if ( ! is_readable ( $ file ) ) { throw new CompressException ( '__exception_compress_file_not_readable' ) ; } // work out path stuff $ old_cwd = getcwd ( ) ; $ path = dirname ( $ file ) ; chdir ( $ path ) ; $ name = $ this -> getArchiveName ( ) ; $ zip = $ this -> getArchiver ( ) ; $ zip -> open ( $ name , \ ZipArchive :: CREATE ) ; if ( file_exists ( $ file ) ) { $ zip -> addFile ( basename ( $ file ) ) ; } if ( $ zip -> status != '0' ) { throw new CompressException ( '__exception_compression' ) ; } $ zip -> close ( ) ; if ( ! $ this -> getKeepOriginal ( ) && file_exists ( $ file ) ) { unlink ( $ file ) ; } if ( $ desination ) { $ desination = realpath ( $ desination ) . DIRECTORY_SEPARATOR . $ name ; copy ( $ name , $ desination ) ; unlink ( $ name ) ; $ name = $ desination ; } else { $ name = $ path . DIRECTORY_SEPARATOR . $ name ; } // reset path chdir ( $ old_cwd ) ; return $ name ; }
Compresses a single file

@param string $file
the full path to the file to compress
@param string $desination
optional the full path to the destination. If none is given then $file is used with the extension appended
Compresses a single file