Skip to content

Instantly share code, notes, and snippets.

@graphicmist
Created June 30, 2017 12:20
Show Gist options
  • Save graphicmist/cbd8b9f8b87d85377651ddb686ad6e68 to your computer and use it in GitHub Desktop.
Save graphicmist/cbd8b9f8b87d85377651ddb686ad6e68 to your computer and use it in GitHub Desktop.
Script to export Images from Magento1x
<?php
require '/var/www/html/app/Mage.php';
Mage::app();
$outputDir = "/home/sslol/images";
$products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('sku');
foreach ($products as $product) {
$id = $product->getData('entity_id');
$sku = $product->getData('sku');
$images = Mage::getModel('catalog/product')->load($id)->getMediaGalleryImages();
if(count($images)) {
echo "Processing SKU-".$sku."\n";
$outputPath = $outputDir.'/'.$sku;
mkdir($outputPath,0777,true);
foreach($images as $image) {
$source = $image['path'];
$relativeFilePathArray = explode("/",$image['file']);
$filename = $relativeFilePathArray[count($relativeFilePathArray) - 1];
$destination = $outputPath."/".$filename;
copy($source, $destination);
}
}
else {
echo "Skipping SKU-".$sku."\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment