setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $dbp->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); switch ($mode) { case "icons": if (@!$dbp->query("SELECT EXISTS(SELECT 1 FROM icons WHERE fid='".$fid."')")->fetch()[0]) { $stmt = $dbp->prepare("INSERT INTO icons VALUES (:fid, :hash, :created, :relative_path, :tool)"); $cmd = $bin_qltool." di ".$shellpath." ".$p['thumb_size']." ".$p['thumb_size']." | base64 --decode > ".$tfile; shell_exec($cmd); $stmt->BindValue(":fid",$fid); if (@filesize($tfile)) { $hash = md5_file($tfile); $stmt->BindValue(":hash",$hash); if ($row = @$dbp->query("SELECT * FROM icons WHERE hash='".$hash."'")->fetchAll()[0]) { $stmt->BindValue(":created",$row['created']); $stmt->BindValue(":relative_path",$row['relative_path']); $stmt->BindValue(":tool",$row['tool']); } else { $dfile = $bpath."/icons/".substr($hash, 0, 2)."/".$hash.".png"; if (!is_dir(dirname($dfile))) { mkdir(dirname($dfile)); } shell_exec("sips -z ".$p['thumb_size']." ".$p['thumb_size']." ".$tfile." --out ".$dfile); $stmt->BindValue(":created",time()); $stmt->BindValue(":relative_path",substr($dfile,strlen($bpath))); $stmt->BindValue(":tool","qltool"); } } $stmt->execute(); } break; } echo "\nHelper (".$mode."): ".basename($pathname)."\n"; ?>