include_once 'inc/declare.php'; include_once 'inc/contentutil.php'; class Photo { public $url; public $name; public $description; public function __toString() { return $this->name; } } $currentPhoto = (isset($id) and is_numeric($id)) ? $id : 0; // Load photo file names into an array from the ./photos folder. if ($photoFolder = opendir("photos")) { $photoArray = array(); // Until all files are read. while ($photo = readdir($photoFolder)) { // If the last 4 characters are '.jpg' if (strripos($photo, ".jpg", 1) == strlen($photo) - 4) { $photoObj = new Photo(); // Put (relative) file path into a variable. Escape characters later after this // path is used within the php to retrieve the image info. $photoURL = "photos/".$photo; // Retrieve image title, or use the filename. Then insert into photo object. $photoTitle = getJPEGData($photoURL, 'title'); if ($photoTitle == "") { $photoTitle = substr($photo, 0, strlen($photo)-4); //$photoTitle = substr($photoTitle, 3, strlen($photoTitle)+1); $photoTitle = str_replace("'", "\'", $photoTitle); } $photoObj->name = $photoTitle; // Retrieve and format image comments. Then insert into photo object. $photoDesc = getJPEGData($photoURL, 'comments'); $photoObj->description = $photoDesc; // Format url to send to Javascript (after it's been used within the PHP). // Apparently the magic quotes aren't applied because of the way it was loaded. // Then insert into photo object. $photoURL = str_replace("'", "\'", $photoURL); $photoObj->url = $photoURL; // Insert thumb object into array at the index prescibed by the filename number. //$photoNumber = substr($photo, 0, 2); $photoArray[] = $photoObj; } } sort($photoArray, SORT_STRING); } function getJPEGData($fileName, $node) { // Returns the title and comments from the image metadata. $fileName = stripslashes($fileName); $exif = exif_read_data($fileName, 'IFD0', true); if ($exif === false) return ""; foreach ($exif as $key => $section) { if ($key == 'IFD0') { foreach ($section as $name => $val) { if (strtolower($name) == strtolower($node)) { $val = addslashes($val); $val = str_replace('\0', '', $val); return $val; } } } } return ""; } $title = "Photo Viewer"; include_once 'inc/head.php'; ?>