Saturday 16 March 2013

create and download zip


<?php

$image = $_REQUEST['img'];
$source = $_SERVER['DOCUMENT_ROOT']."/sourcefolder/".$image
$orderid = $_REQUEST['orderid'];

$zip = new ZipArchive();
$DestFilePath=$orderid.".zip";
$destinat  = Mage::getBaseDir().'/zip/'.$DelFilePath;
$destinat = $_SERVER['DOCUMENT_ROOT']."/destination/".$DestFilePath;
if(file_exists($destinat)) {
    unlink ($destinat);
}
if ($zip->open($destinat, ZIPARCHIVE::CREATE) != TRUE) {
        die ("Could not open archive");
}
$zip->addFromString(basename($source), file_get_contents($source));
$zip->close();

/**************************  Download file ********************************/
$file = $orderid.'.zip';
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header( "Content-Disposition: attachment; filename=".basename($file));
header( "Content-Description: File Transfer");
@nl2br(readfile($file));
/**************************  end Download file ********************************/
?>

No comments: