Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create file directory structure for downloadable Magento products & move files accordingly
<?php
foreach (new DirectoryIterator('files/') as $file) {
if ($file->isFile()) {
$file_name = $file->getFilename();
$name = strtolower($file_name);
$letter1 = $name[0];
$letter2 = $name[1];
// Create first directory
if (!file_exists('media/downloadable/files/links/' . $letter1)) {
mkdir('media/downloadable/files/links/' . $letter1, 0777, true);
}
// Create subdirectory
if (!file_exists('media/downloadable/files/links/' . $letter1 . '/' . $letter2)) {
mkdir('media/downloadable/files/links/' . $letter1 . '/' . $letter2, 0777, true);
}
// Move file
rename('files/' . $file_name, 'media/downloadable/files/links/' . $letter1 . '/' . $letter2 . '/' . $name);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.