function parseFolder($tempFolderPath, $tempThumbnailPath) { $dir = opendir("{$tempFolderPath}"); while (false !== ($album = readdir($dir))) { //print $imagePath.'/'.$album . " - " . is_dir($imagePath."/".$album). '<br>'; //print $album . ' <BR/>'; if ($album != "." && $album != "..") { $thisImagePath = $tempFolderPath . "/" . $album; $thisThumbnailPath = $tempThumbnailPath . "/" . $album; //print $thisAlbumPath . " is here"; $innerdir = opendir("{$thisImagePath}"); while (false !== ($innerfile = readdir($innerdir))) { //print "$innerfile : " . is_file($innerfile) . '<br>'; $isAlbum = 0; if (is_file($thisImagePath . '/' . $innerfile)) { $isAlbum = 1; break; } } if ($isAlbum == 1) { //print $thisImagePath . " is getting processed"; createThumbsFromFolder($thisImagePath, $thisThumbnailPath); } else { if (is_dir($thisImagePath)) { //print $thisImagePath . ' is a set <BR/>'; mkdir("{$thisThumbnailPath}", 0777); parseFolder($thisImagePath, $thisThumbnailPath); } } } } }
*/ // Get options- cmd line or GET $options = getopt('p:', array('path:')); $path = isset($options['p']) ? $options['p'] : (isset($options['path']) ? $options['path'] : null); if (null === $path) { $self = $_SERVER['SCRIPT_NAME']; $path = urldecode($_SERVER['REQUEST_URI']); if (substr($path, 0, strlen($self)) === $self) { // strip script name if called as /coverart.php/path/to/file $path = substr($path, strlen($self) + 1); } $path = '/mnt/' . $path; } // does file exist and contain image? getImage($path); echo "done"; die; // directory - try all files if (is_dir($path)) { // make sure path ends in / if (substr($path, -1) !== '/') { $path .= '/'; } parseFolder($path); } else { // file - try all files in containing folder $path = pathinfo($path, PATHINFO_DIRNAME) . '/'; parseFolder($path); } // nothing found -> default cover header('Location: /images/default-cover.jpg');
function drawFolderContentJustified($_containerWidth, $_folderId, $_byDate = false, $_curPage = -1) { $html = ''; $html .= '<script> var imgsInPage = [];'; $imgList = array(); $folderImgs = parseFolder($_folderId, $_curPage - 1); $curDate = '*'; $imgList[$curDate] = array(); foreach ($folderImgs as $fileDatas) { $html .= 'imgsInPage.push( ' . $fileDatas['id'] . ');'; if ($_byDate && $curDate != substr($fileDatas['exif_date_crea'], 0, 10)) { $curDate = substr($fileDatas['exif_date_crea'], 0, 10); } $imgList[$curDate][] = array('id' => $fileDatas['id'], 'filename' => $fileDatas['filename'], 'src' => 'thumbs/' . $_folderId . '/thumb_' . $fileDatas['id'] . '_200.jpg', 'link' => 'image.php?img_id=' . $fileDatas['id'], 'exif_date_crea' => $fileDatas['exif_date_crea']); } $html .= '</script>'; if ($_byDate) { unset($imgList['*']); foreach ($imgList as $date => $list) { $html .= '<br><h5><span class="glyphicon glyphicon-calendar"></span> ' . $date . '</h5>'; $html .= drawThumbsImages($_containerWidth, $list); $html .= '<br>'; } } else { $html .= drawThumbsImages($_containerWidth, $imgList['*']); } return $html; }