Home > Backend Development > PHP Tutorial > PHP reads image files in a directory_PHP tutorial

PHP reads image files in a directory_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:45:21
Original
1003 people have browsed it

php reads image files in the directory This article is a PHP code that reads image files in a directory. It uses opendir to open the directory and then obtains the file suffix name to determine whether it is the specified file.

php tutorial to read image files in the directory
This article is a PHP code that reads image files in a directory. It uses opendir to open the directory and then obtains the file suffix name to determine whether it is 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 an 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 '

';

$i++;
}
}

closedir($dir_handle);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/633023.htmlTechArticlephp reads image files in the directory. This article is a php that reads image files in the directory. Code, he Use opendir to open the directory and then get the file suffix name to determine whether it is the specified file...
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template