18c05-1.php
来自「介绍PHP5的给类型函数应用」· PHP 代码 · 共 82 行
PHP
82 行
<style>div { text-align: center; border: 2px solid black; padding: 5px; margin: 10px;}ul { font-size: 9px; text-align: left;}</style><?php// Define a path - We are assuming that this will be a relative path working// both in the filesystem, and through the web for links:$path = "photos/";// Open the directory $do = dir($path);// Loop through it, looking for any/all JPG files:while (($file = $do->read()) !== false) { // Parse this for the extension $info = pathinfo($path . $file); // Continue only if this is a Jpeg if (strtolower($info['extension']) == 'jpg') { // We found one! Start a DIV to display & link to this: echo "<div><a href=\"{$path}{$file}\">"; // Let's try to grab the graphic, and if so, display it. if ($thumb = exif_thumbnail($path . $file, $width, $height, $type)) { // We got one. Therefore first figure out the mime type of it $mime = image_type_to_mime_type($type); // Now we are going to use an HTML trick, and embed the graphic // directly into the webpage as base64 encoded data $encoded = base64_encode($thumb); echo "<img src=\"data:{$mime};base64,{$encoded}\" /><br />"; } // In either case, place the name of the file as part of the link: echo $file, "</a>\n"; // Now let's read in all the Exif data: if ($exif = exif_read_data($path . $file)) { // We got it. So start an unordered list to display it all echo "<ul>\n"; // We need to loop through each 'section' of this data foreach ($exif as $section => $sectiondata) { // If sectiondata is an array, start a new list: if (is_array($sectiondata)) { // Output the section name, and start a new list echo "<li>{$section}<ul>\n"; // Loop through this section now foreach ($sectiondata as $name => $data) { // Output this line of data echo "<li>{$name} = ", htmlspecialchars($data), "</li>\n"; } // Close our section off echo "</ul></li>\n"; } else { // It's not really a section, its got data. Echo it echo "<li>{$section} = ", htmlspecialchars($sectiondata), "</li>\n"; } } // Close the entire list off echo "</ul>\n"; } // Close the div tag echo "</div>\n"; }}?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?