Basit kod?

3 Cevap

Birisi (http üzerinden) uzak bir sunucuda bulunan bir bilinen bir zip dosyası açan bir php komut dosyası bir çalışma örnek kodu veya gelin yayınlamak ve arama komut dosyası olarak aynı sunucuda bir klasöre bu zip dosyasının içeriğini ayıklar miyim?

Server A calls out for zip file located on Server B
Server B sends the zip file over to server A
Server A extracts the contents of the Zip to Directory C (pub_html) on Server A

Ben bu işe almak için nasıl etrafında ve çevresinde devam ettik ve örneklerle dolu süper basit olması gerektiği gibi gerçekten görünüyor, ama hiçbiri bulabilirsiniz.

3 Cevap

Buyurun.

Buna üst $ dosya ve $ dest_folder Alter. $ Dest_folder şu anda (PHP komut dosyası kendisi bulunduğu) geçerli klasöre ayarlanır.

<?php

$filename = 'http://someplace.com/somezipfile.zip';
$dest_folder = '.';

$out_file = fopen(basename($filename), 'w');
$in_file = fopen($filename, 'r');
while ($chunk = fgets($in_file)) {
    fputs($out_file, $chunk);
}
fclose($in_file);
fclose($out_file);

$zip = new ZipArchive();
$result = $zip->open(basename($filename));
if ($result) {
    $zip->extractTo($dest_folder);
    $zip->close();
}

?>

documentation basit bir durum gösterir:

<?php

  $zip = new ZipArchive;
  $res = $zip->open('test.zip');
  if ($res === TRUE) {
    echo 'ok';
    $zip->extractTo('test');
    $zip->close();
  } else {
    echo 'failed, code:' . $res;
  }

?>

Size uzak arşiv ne kadar büyük bağlı olarak, komut yürütme zaman dikkatli olmak isteyeceksiniz, ve ne kadar hızlı sunucu uzak sunucu ile iletişim kurabilir.

Ok first i suggest you write a curl function or class which fetsches for you the zip file and stores them to a temp folder or somewhere else. After Saving the zip file i assume you know the name of it. Then you could simple do this

<?php
    $zip = new ZipArchive;
    $zip->open('test.zip');
    $zip->extractTo('./');
    $zip->close();
?>

Bu çıkarma bir zip dosyası için basit olsa. Bazı hatayı yakalamaktır gerekiyor ama bu iş Fun :-) var yok