Code: Select all
/**
* @return array
* @param array $img_array
* @param string $width
* @param string $height
* @desc returns thumbnails in path
**/
function get_thumbs($img_array, $width, $height) {
// create filesystem
global $filesystem;
foreach ($img_array as $image) {
// file info
$info = $filesystem->path_info($image);
$dir_name = $info['dirname'].'/';
$file_name = $info['basename'];
$file_ext = $info['extension'];
$thumb_dir = $dir_name.'thumbs/';
$thumb_path = $thumb_dir.$file_name;
// thumbnail exists
if (file_exists($thumb_path)) {
$thumb_array[] = $thumb_path;
}
else {
// first create directory if not there
if (!file_exists($thumb_dir)) {
$mkdir = mkdir($thumb_dir);
if (!$mkdir) {
// error
echo 'Unable to create directory: '.$thumb_dir.'';
exit;
}
}
// now put thumbs in directory
$thumb = $this->generate_thumbs($image, $thumb_path, $width, $height);
if ($thumb) {
// thumb creation was successful
$thumb_array[] = $thumb_path;
}
else {
// errror
echo 'Unable to generate thumbnail '.$thumb_path.'<br>';
exit;
}
}
}
return $thumb_array;
}first time i run it in /images -> dir is created /images/thumbs/ and thumbs are put in that dir
second time i run it in /images -> dir is created /images/thumbs/thumbs and thumbs are put in that dir, and the resulting $thumb_array contains all the thumbnails in /images down, thus each time I run it, the array gets bigger as it is creating a deeper /thumbs directories.
I'm unsure why it is doing this, any help would be appreciated, cheers.