Zend - The PHP Company




Files and Directories

Add Code


list and link to all images, and include all their information  

Type: code fragment
Added by: armelino
Entered: 28/01/2002
Last modified: 02/12/2001
Rating: - (fewer than 3 votes)
Views: 6740
This code allows you to dynamically list a directory's image files, creates links to them, and tells you their size in pixels and kilobytes.


<?php
    $handle
=opendir('.');
    
$strSought "JPG";
    
$num 0


    while (
$file readdir($handle)) {
    if (
$strSought == substr($file, -3)) {
        
$num $num 1;
    }
    }
    
closedir($handle); 

    
$handle=opendir('.');
    echo 
"There are $num files!<br><br>";

    echo
"<table>";
    echo 
"<tr><td colspan = 5>Files:</td></tr>"

    while (
$file readdir($handle)) {
    if (
$strSought == substr($file, -3)) {
        
$size GetImageSize($file);
        
$fullsize intval(filesize($file)*.001);
            echo 
"<tr><td><a href=$file>$file</a></td><td>&nbsp;&nbsp;<b>$size[0]</b></td><td>&nbsp;by</td><td>&nbsp;<b>$size[1]</b>:</td><td>&nbsp;$fullsize kb</td></tr>";
        }
    }
    
closedir($handle);
    echo
"</table>";
?>


Usage Example




Rate This Script





Search



This Category All Categories