Skip to content
This repository has been archived by the owner on Apr 5, 2018. It is now read-only.

Commit

Permalink
Use original filename in zip
Browse files Browse the repository at this point in the history
  • Loading branch information
Bob Olde Hampsink committed Oct 10, 2015
1 parent e491f02 commit 1e8ba85
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions services/ZipAssetsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,39 @@ public function download($files, $filename)
// Set destination zip
$destZip = craft()->path->getTempPath().$filename.'_'.time().'.zip';

// Create the zipfile
IOHelper::createFile($destZip);
// Create zip
$zip = new \ZipArchive();

// Loop through assets
foreach ($assets as $asset) {
// Open zip
if ($zip->open($destZip, $zip::CREATE) === true) {

// Get asset source
$source = $asset->getSource();
// Loop through assets
foreach ($assets as $asset) {

// Get asset source type
$sourceType = $source->getSourceType();
// Get asset source
$source = $asset->getSource();

// Get asset file
$file = $sourceType->getLocalCopy($asset);
// Get asset source type
$sourceType = $source->getSourceType();

// Add to zip
Zip::add($destZip, $file, dirname($file));
// Get asset file
$file = $sourceType->getLocalCopy($asset);

// Remove the file
IOHelper::deleteFile($file);
// Add to zip
$zip->addFromString($asset->filename, IOHelper::getFileContents($file));

// Remove the file
IOHelper::deleteFile($file);
}

// Close zip
$zip->close();

// Return zip destination
return $destZip;
}

// Return zip destination
return $destZip;
// Something went wrong
throw new Exception(Craft::t('Failed to generate the zipfile'));
}
}

0 comments on commit 1e8ba85

Please sign in to comment.