Bir ZIP dosyasını işleme yardıma ihtiyacınız var

0 Cevap php

Bu benim senaryo:

  • Ben bir zip dosya upload
  • Zip dosyası içinde her dosyayı kontrol
  • Eğer dosya! = Görüntü, daha sonra hedef dosya taşımak
  • dosya == görüntü varsa, görüntüyü yeniden boyutlandırmak ve hedefe taşımak

Ben etrafında googled ve görülen farklı çözümler, ancak hiçbiri burada bir nihai hedefe onları kaydetmeden önce dosyaları işleyebilir.

Bu şimdiye kadar var fonksiyonudur:

  // Extract zip file and return files in an array. 
  private function processZip() {
    $zip = new ZipArchive;    
    $tmp_dir = FB_PLUGIN_DIR.'tmp/';

    // Extract files to tmp dir
    if ($zip->open($this->file['tmp_name']) === TRUE) {
      //Check if temp dir exists. If not, create one.
      if (!is_dir($tmp_dir)) {
        mkdir($tmp_dir, 0700);
      }

      $zip->extractTo($tmp_dir);
      $zip->close();

    /* Process extracted files */ 

    foreach(glob($tmp_dir.'*.*') as $filename) {

        // Somehow get MIME type here without using 'finfo' and 'mime_content_type'
        // I haven't installed PEAR and 'mime_content_type' is decapricated.
    }      

      return '1'; // success
    } else {
      return "0"; // fail
    } 
  } 

Ben burada doğru yönde gidiyorum emin değilim. Nedense ben "ZIP döngü" iken dosyaları işlemek gerekir düşünüyorum.

Ben MIME türü belirlemeleri, ZIP dosyası dosyaları okumak ve daha sonra işlem dosyası bir yolu var mı?

I found this example: http://www.java-samples.com/showtutorial.php?tutorialid=985
I think it's close to what I need. But not sure what to modify.

0 Cevap