server side oprettede zip kan ikke udpakkes på mac?
HejJeg har efterhånden i 2 uger brugt min fritid på at finde en løsning på mit php problem.
Problemet kort:
Jeg skal zippe nogle filer server side og sende dem til brugeren når vedkommende klikker på et link.. det virker 100% på PC. Men ikke på mac. Når mac udpakker .zip filen, kommer der en .cpgz fil ud, som fylder fuldstændig det samme som .zip filen.
se her: [img] http://imageshack.dk/imagesfree/Kn745865.jpg[/img]
PC Zip, har det noget at sige?
Her er min kode med php egen zip class zipArchive:
<?php
function makeZip($imgArr, $priceArr) {
// START ZIP FILE
$zip = new ZipArchive();
// folder
$dir = "zip/files/";
// array count
$arrCount = 1;
$arrPriceCount = 1;
// naming the zip file
$today = date("d_F_y");
$archive_file_name= 'download' . $today . '.zip';
if ($zip->open($archive_file_name, ZIPARCHIVE::CREATE )=== TRUE) {
// reset product informations..
$output = "";
foreach($productList as $product)
{
$price = '';
$price = $priceArr[$arrPriceCount];
$arrPriceCount++;
$output .= 'Name: ' . "\r\n" . $product->getName() . "\r\n" . "\r\n";
$output .= 'Item ID: ' . "\r\n" . $product->getSku() . "\r\n" . "\r\n";
$output .= 'Description: ' . "\r\n" . $product->getDescription() . "\r\n" . "\r\n";
$output .= 'Price: ' . "\r\n" . $price . "\r\n";
// CREATE FILES
// rename product name
$_fra = $product->getName();
$_replacers = array(" ", "-", "!", ":", ";", "#", "@", "'", "æ", "ø", "å", "Æ", "Ø", "Å", "Ã", "¸", "¥", "¦", "†", "˜", "…", "/");
$filename = str_replace($_replacers, "_", $_fra);
// Image files
$imagePath = $dir . $filename . ".jpg";
$file = $imgArr[$arrCount];
if (!copy($file, $imagePath)) {
echo "failed to copy $file...\n";
}
$imageName = $filename . "_highres.jpg";
$zip->addFile($imagePath,$imageName);
$arrCount++;
$imagePathSmall = $dir . $filename . "small.jpg";
$file_small = $imgArr[$arrCount];
if (!copy($file_small, $imagePathSmall)) {
echo "failed to copy $file...\n";
}
$imageNameSmall = $filename . "_lowres.jpg";
$zip->addFile($imagePathSmall,$imageNameSmall);
$arrCount++;
// TXT FILE !
$txtpath = $dir . $filename . ".txt";
$strlength = strlen($output);
$create = fopen($txtpath, "w");
$write = fwrite($create, $output, $strlength);
$close = fclose($create);
$textFileName = $filename . ".txt";
$zip->addFile($txtpath,$textFileName);
}
}
$zip->close();
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=".basename ($archive_file_name).";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($archive_file_name));
readfile($archive_file_name);
// delete temporary content
@unlink($archive_file_name);
if($bib = @opendir($dir)) {
while (false !== ($fil = readdir($bib))) {
if($fil != "." && $fil != ".." && !ereg("^\..+", $fil)) {
unlink($dir."/".$fil);
}
}
closedir($bib);
}
}
?>
Skyd løs med mulige løsninger. Alt kan hjælpe mig :)