Kayıtlar

php ile dosyaları zip olarak kaydetme etiketine sahip yayınlar gösteriliyor

PHP ile zip arşivi oluşturma ve dosyaları zip arşivine ekleme

Aşağıdaki kodlar sayesinde sunucuda,hostingde bulunan dosyaları zip arşivine ekleyebilirsiniz.Kısacası PHP ile zip arşivi nasıl oluşturulur onu öğreneceğiz. Fonksiyon: function createZIP( $files = array (), $output = '' , $overwrite = false) { if ( file_exists ( $output ) && ! $overwrite ) { return false; } $zip = new ZipArchive(); if ( $zip ->open( $output , $overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) { return false; } if ( count ( $files )) { foreach ( $files as $file ) { $zip ->addFile( $file , $file ); } $zip ->close(); return file_exists ( $output ); } else { return false; } } Nasıl kullanılır? $files_to_zip = array (      'dosya.txt' ,      'resim.jpg' ,      'dosya2.text' ,      'klasor/dosya.text' ); // $result = createZIP( $files_to_zip , 'arsivadi.zip' );