图片库系统与搜索引擎使用php



我正在尝试制作一个带有关键字的图片库系统。每个图像都有一个包含几个变量的.php文件:

    $keywords = 'Keywords that describe the image';
    $src = 'directory path leading to the image';
    $other = 'any specific remarks about the image'; 

每个图像的文件都存储在一个名为 imageinfo 的目录中。如何使目录中文件中列出的所有图像imageinfo显示在一个.php文件中?它们都具有相同的变量名称。我可以制作一个搜索引擎系统来搜索文件吗?这很难解释,如果你不明白,我理解 - 随意拿起健怡可乐,来评论中写下你的问题!

试试这个:
(您必须填写正确的图像信息文件夹)

<?php
// Folder with all the Info PHP files
$infodir = __DIR__ .'/imageinfo/';
// read Folder contens
$files = scandir( $infodir );
// Array to store all image infos
$allimages = array();
// loop, file for file
foreach ($files  as $file) {
    // . and .. are in the array of files, but we don't need them
    if( $file != '..' && $file != '.' ){
        //path to actual Image Info file
        $thisfile = $infodir.'/'.$file;
        //Check if file exists
        if( is_file( $thisfile ) ){
            //parse file
            include( $thisfile );
            //add vars to Array
            $allimages[] = array(
                'keywords' => $keywords,
                'src' => $src,
                'other '=> $other
            );
        }
    }
}
//Output Data of all files
echo '<pre>';
print_r( $allimages );
echo '<pre>';

//show images in browser
foreach ($allimages as $image ) {
    echo '<div class="img">';
    echo '<img src="'.$image['src'].'" title="" alt="" >';
    echo '<br />';
    echo $image['keywords'];
    echo '<br />';
    echo $image['other'];
    echo '</div>';
}
?>

最新更新