PHP Download Directory as Zip Archive

Want to download any directory and its content as zip file? Please use following code where we have used ZipArchive object.

// Get real path for our folder
		$rootPath = realpath($dir);		
		// Initialize archive object
		$zip = new ZipArchive();
		$archive = '';		
		$res = $zip->open($archive, ZipArchive::CREATE);
		// Create recursive directory iterator
		/** @var SplFileInfo[] $files */
		$files = new RecursiveIteratorIterator(
			new RecursiveDirectoryIterator($rootPath),
		foreach ($files as $name => $file)
			// Skip directories (they would be added automatically)
			if (!$file->isDir())
				// Get real and relative path for current file
				$filePath = $file->getRealPath();
				$relativePath = substr($filePath, strlen($rootPath) + 1);
				// Add current file to archive
				$zip->addFile($filePath, $relativePath);
		// Zip archive will be created only after closing object
		header('Content-Type: application/zip');
		header('Content-disposition: attachment; filename='.$archive);
		header('Content-Length: '.filesize($archive));

Magento Version Checkout Process Not Working After Update

Go to your theme folder and then navigate through this –


if this file is not present copy one from base default directory.

that is /app/design/frontend/base/default/template/checkout/onepage/payment.phtml


<?php echo $this->getChildHtml('methods') ?>

change to:

<fieldset id="checkout-payment-method-load">
<?php echo $this->getChildHtml('methods') ?>

Magento Indexing Script

Last time I added how to run reindex process programmatically. The problem with previous script is that process update successfully but when I went to search and try to find any sku that shows no result.

Another solution that works is as follow:

require_once './app/Mage.php';
$processes = array();
$collection = Mage::getSingleton('index/indexer')->getProcessesCollection();
foreach ($collection as $process) {
	if ($process->getIndexer()->isVisible() === false) {
	$processes[] = $process;
try {
	foreach ($processes as $process) {
		/* @var $process Mage_Index_Model_Process */
		Mage::dispatchEvent($process->getIndexerCode() . '_shell_reindex_after');
} catch (Exception $e) {
	echo('Exception in Index Index Referesh' . $e -> getMessage() . PHP_EOL);

Magento Test SMTP Detail Script

If we want to check that given SMTP detail are working or not, here is a small script that we can use. We are using Zend mail for sending this.

require_once './app/Mage.php';
$port = 465; //465,587
$ssl = "SSL"; // SSL/TLS
$username = "username";
$password = "password";
$host = ""; // for Google host will be
$config = array('ssl' => $ssl, 'port' => $port, 'auth' => 'login', 'username' => $username, 'password' => $password);
$smtpConnection = new Zend_Mail_Transport_Smtp($host, $config);
$mail = new Zend_Mail();
$mail->setBodyText('This is the text of the mail.');
$mail->setFrom('', 'From');
$mail->addTo('', 'To');

Magento extension that we can use for SMTP configuration –

Load CMS Page using SSL

In Magento if you have SSL enabled at your server and you want to display any page using https SSL. You can use link in CMS page or in phtml files.

<li><a title="CMS Page" href="{{store url='page-identifier' _secure="true" )}}">CMS Title</a></li>
//or if its not working use force secure
<li><a title="CMS Page" href="{{store url='page-identifier' _forced_secure="true" )}}">CMS Title</a></li>
//In Phtml files -