'Invalid ID', 'images' => array())); exit; } // Get the anlage to know the socid $anlage = new Anlage($db); if ($anlage->fetch($anlageId) <= 0) { echo json_encode(array('error' => 'Element not found', 'images' => array())); exit; } // Get images for this element $anlagefile = new AnlageFile($db); $files = $anlagefile->fetchAllByAnlage($anlageId, 'image'); $images = array(); foreach ($files as $file) { $images[] = array( 'id' => $file->id, 'name' => $file->filename, 'url' => $file->getUrl(), 'thumb' => $file->getThumbUrl() ?: $file->getUrl(), ); } echo json_encode(array('images' => $images));