Last active
May 10, 2017 10:09
-
-
Save steverobbins/e6bbb8c6272f652cfcf0 to your computer and use it in GitHub Desktop.
Download product media images to your local Magento store without rsync/ftp.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$range = array_merge(range('a', 'z'), range('A', 'Z'), range(0, 9), array('_')); | |
foreach ($range as $a) foreach ($range as $b) mkdir("$a/$b", 0777, true); | |
$db = new PDO('mysql:127.0.0.1;dbname=magento', 'root', 'root'); | |
//$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); | |
$result = $db->query('select distinct value from catalog_product_entity_media_gallery'); | |
foreach ($result as $row) { | |
$path = dirname(__FILE__) . '/' . trim($row['value'], '/'); | |
if (!file_exists($path)) { | |
echo "{$row['value']}\n"; | |
exec("curl -s -o $path http://static.example.com/media/catalog/product{$row['value']}"); | |
} | |
} |
Author
steverobbins
commented
Feb 10, 2015
Thank you so much for this, it has saved me a huge amount of work and was so simple to use!
There were a couple of changes I had to make to fit my setup in case it's of use to anybody else:
-
Add '-' (hyphen) to the array of folders created e.g.:
$range = array_merge(range('a', 'z'), range('A', 'Z'), range(0, 9), array('_', '-')); -
Add the "host=" parameter back into the PDO constructor (running PHP 5.6.25):
$db = new PDO('mysql:host=127.0.0.1;dbname=magento', 'root', 'root');
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment