Windows PHP ZipArchive bozmak

0 Cevap php

Ben fotoğraflar içeren bir zip dosyası oluşturmak ve daha sonra indirmek için tarayıcıya kadar hizmet PHP'nin ZipArchive sınıfını kullanıyorum. İşte benim kod:

/**
 * Grabs the order, packages the files, and serves them up for download.
 *
 * @param string $intEntryID 
 * @return void
 * @author Jesse Bunch
 */
public static function download_order_by_entry_id($intUniqueID) {

    $objCustomer = PhotoCustomer::get_customer_by_unique_id($intUniqueID);

    if ($objCustomer):

        if (!class_exists('ZipArchive')):
            trigger_error('ZipArchive Class does not exist', E_USER_ERROR);
        endif;

        $objZip = new ZipArchive();
        $strZipFilename = sprintf('%s/application/tmp/%s-%s.zip', $_SERVER['DOCUMENT_ROOT'], $objCustomer->getEntryID(), time());

        if ($objZip->open($strZipFilename, ZIPARCHIVE::CREATE) !== TRUE):

            trigger_error('Unable to create zip archive', E_USER_ERROR);

        endif;          

        foreach($objCustomer->arrPhotosRequested as $objPhoto):

            $filename = PhotoCart::replace_ee_file_dir_in_string($objPhoto->strHighRes);
            $objZip->addFile($filename,sprintf('/press_photos/%s-%s', $objPhoto->getEntryID(), basename($filename)));

        endforeach;

        $objZip->close();

        header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($strZipFilename)).' GMT',  TRUE, 200);
        header('Cache-Control: no-cache', TRUE);
        header('Pragma: Public', TRUE);
        header('Expires: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT', TRUE);
        header('Content-Length: '.filesize($strZipFilename), TRUE);
        header('Content-disposition: attachment; filename=press_photos.zip', TRUE);

        header('Content-Type: application/octet-stream', TRUE);

        ob_start();
        readfile($strZipFilename);
        ob_end_flush();
        exit;

    else:

        trigger_error('Invalid Customer', E_USER_ERROR);

    endif;

}

Bu kod tüm tarayıcılar ama IE ile gerçekten iyi çalışıyor. IE, dosya doğru indirir, ama zip arşivi boştur. Dosyaları ayıklamak için çalışırken Windows zip arşivi bozuk olduğunu söylüyor. Herkes önce bu sorunu oldu?

Edit Güncelleme: @ profitphp gelen öneri sonra, ben bu benim başlıkları değişti:

header("Cache-Control: public");
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
//header("Content-Description: File Transfer");
//header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=\"pressphotos.zip\"");
//header("Content-Transfer-Encoding: binary");
header("Content-length: " . filesize($strZipFilename));

Ayrıca, burada Firefox ile açtıktan sonra Windows hata bir ekran görüntüsü:

alt text

Bu hata, Windows üzerinde IE ve Firefox oluşur. Bu Mac çalışıyor. Ayrıca, Windows, dosya boyutu doğru görünmektedir:

alt text

Edit #2 Bu konu sovled edilir. Aşağıda benim cevaba bakınız.

0 Cevap