PHP Read directory image file _php tutorial

Source: Internet
Author: User
PHP Read Directory Image file This is a PHP read directory like file Oh, code, he used the Opendir to open the directory and then get the file suffix name, determine whether the specified file.

PHP Tutorial Read directory image file
This paragraph is a PHP read directory like file Oh, code, he used the Opendir to open the directory and then get the file suffix name, determine whether the specified file.
*/

$directory = ' gallery ';

$allowed _types=array (' jpg ', ' jpeg ', ' gif ', ' PNG ');
$file _parts=array ();
$ext = ";
$title = ";
$i = 0;

$dir _handle = @opendir ($directory) or Die ("There is a error with your image directory!");

while ($file = Readdir ($dir _handle))
{
if ($file = = '. ' | | $file = = ' ... ') continue;

$file _parts = Explode ('. ', $file);
$ext = Strtolower (Array_pop ($file _parts));

$title = Implode ('. ', $file _parts);
$title = Htmlspecialchars ($title);

$nomargin = ";

if (In_array ($ext, $allowed _types))
{
if (($i + 1)%4==0) $nomargin = ' Nomargin ';

Echo '

'. $title. '
';

$i + +;
}
}

Closedir ($dir _handle);

http://www.bkjia.com/PHPjc/633023.html www.bkjia.com true http://www.bkjia.com/PHPjc/633023.html techarticle PHP Read directory image file This is a PHP read directory like file Oh, code, he used the Opendir to open the directory and then get the file suffix name, to determine whether the specified file ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.