Codice PHP:
$filetypes = array(".png", ".PNG", ".jpg", ".JPG", ".jpeg", ".JPEG", ".gif", ".GIF");$basedir = './immagini/gallery';$currentdir = '';if(isset($_GET['f']) ? $_GET['f'] : '') { $currentdir = '/'.$_GET['f'].'/'; }
function scandirSorted($path) { $sortedData = array(); $data1 = array(); $data2 = array(); foreach(scandir($path) as $file) { if(!strstr($path, '..')) { if(is_file($path.$file)) { array_push($data2, $file); } else { array_push($data1, $file); } } } $sortedData = array_merge($data1, $data2); return $sortedData; }
function strpos_arr($haystack, $needle) { if(!is_array($needle)) { $needle = array($needle); } foreach($needle as $what) { if(($pos = strpos($haystack, $what)) !== false) { return $pos; } } return false; }
function addThumb($filename) { $filename = array_reverse(explode('.', $filename)); $filename[0] = 'smpgthumb.'.$filename[0]; $filename = implode('.', array_reverse($filename)); return $filename; }
if(is_dir($basedir.$currentdir)) { $folder = array_diff(scandirSorted($basedir.$currentdir), array('..', '.', 'Thumbs.db', 'thumbs.db', '.DS_Store')); }
foreach($folder as $item) { if(!strstr(isset($_GET['f']), '..')) { if(!strstr($item, 'smpgthumb')) { if(strpos_arr($item, $filetypes)) { if(file_exists($basedir.$currentdir.'/'.addThumb($item))) { echo('<a href="'.str_replace('//', '/', str_replace(' ', '%20', $basedir.$currentdir.'/'.$item)).'" data-lightbox="roadtrip"><img src="'.str_replace('//', '/', str_replace(' ', '%20', $basedir.$currentdir.'/'.addThumb($item))).'" class="img" alt=""></a>'); } else { echo('<a href="'.str_replace('//', '/', str_replace(' ', '%20', $basedir.$currentdir.'/'.$item)).'" data-lightbox="roadtrip"><img src="php/thumb.php?file='.str_replace('//', '/', str_replace(' ', '%20', $basedir.$currentdir.'/'.$item)).'" class="img" alt=""></a>'); } } else { echo('<a href="?f='.str_replace('//', '/', str_replace(' ', '%20', $currentdir.'/'.$item)).'">'.$item.'</a>'); } } } }?>
Secondo me bisognerebbe modificare qualcosa nell'ultima parte di codice quando vengono creati i collegamenti.