// images $images = array(); // An array which will hold all our images $lines = new SPLFileObject($basePath . DIRECTORY_SEPARATOR . 'captions.txt'); // Main code // @TODO Open directory and captions file using some SPL classes $di = new DirectoryIterator($basePath); // @TODO loop directory foreach ($di as $file) { // exclude . and .. + we don't want directories if (!$file->isDot() && !$file->isDir()) { // If it's a '.jpg', add it onto an array named $images // Use an associative array so you can store the filename, and caption if ($file->getExtension() === 'jpg') { $images[] = array('url' => $baseUrl . DIRECTORY_SEPARATOR . $file, 'caption' => $lines->current()); $lines->next(); } } } ?> <!doctype html> <html> <head> <title>Images</title> <meta charset="utf-8" /> <style> body { font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", sans-serif; font-weight: 300; font-size: 14px;
// images $images = array(); // Main code // Open dir and captions $di = new DirectoryIterator($basePath); $captions = new SPLFileObject($basePath . DIRECTORY_SEPARATOR . 'captions.txt'); // loop directory foreach ($di as $file) { // We only want .jpg if ($file->getExtension() == 'jpg') { // get the caption $caption = $captions->current(); // store the image array_push($images, array('url' => 'images/' . $file, 'caption' => str_replace(PHP_EOL, '', $caption))); // move captions pointer to next caption $captions->next(); } } ?> <!doctype html> <html> <head> <title>Images</title> <meta charset="utf-8" /> <style> body { font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", sans-serif; font-weight: 300; font-size: 14px; line-height: 1.2;