-
-
Save CodeBrauer/edab1838c0aa5b33cedd to your computer and use it in GitHub Desktop.
recursive directory batch file processing with shell exec
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 | |
// not tested - just for logical demonstration | |
$path = [ | |
'source' => '/source_files/', | |
'thumbnails' => '/public_html/images/', | |
]; | |
function thumbnail_exists($file, $type) { | |
global $path; | |
// valid types: png, web, watermarked | |
$valid_types = ['png', 'web', 'watermarked']; | |
if (!in_array($type, $valid_types)) | |
return [false, 'No valid type given']; | |
$file = str_replace($path['source'], $path['thumbnail'], $file); | |
return file_exists($file); | |
} | |
$objects = new RecursiveIteratorIterator( | |
new RecursiveDirectoryIterator($path['source']), | |
RecursiveIteratorIterator::SELF_FIRST | |
); | |
// skip '.' and '..' in unix folders | |
$objects->setFlags(FilesystemIterator::SKIP_DOTS); | |
foreach ($objects as $name => $object) { | |
if ($object->isFile()) { | |
if (strtolower($object->getExtension()) === 'tif') { | |
if (!thumbnail_exists($object->getPathname(), 'png')) { | |
shell_exec('./convert.sh command_1'); | |
} | |
if (!thumbnail_exists($object->getPathname(), 'web')) { | |
shell_exec('./convert.sh command_2'); | |
} | |
if (!thumbnail_exists($object->getPathname(), 'watermarked')) { | |
shell_exec('./convert.sh command_3'); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment