如何在HTML上加载PHP图像库?

时间:2017-05-13 23:57:22

标签: php html

我有一个使用Lightbox插件的基于PHP的图库。当我在MAMP上运行时,它在本地服务器上运行良好。 但是,当我将文件上传到我的网站的SFTP客户端时,它会失败。

我有以下代码:

<?php

$directory = 'SpringPhotos17';
$thumbsdirectory = 'SpringPhotos17/_thumb';

$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 '
        <div class="pic '.$nomargin.'" style="background:url('.$thumbsdirectory.'/'.$file.') no-repeat 50% 50%;">
        <a href="'.$directory.'/'.$file.'" title="'.$title.'" target="_blank">'.$title.'</a>
        </div>';

        $i++;
    }
}

closedir($dir_handle);

?>

我在图片库的HTML代码中插入了这个PHP代码。在网站上,它出现:

'.$title.'

如何解决此问题?感谢您的时间和提前帮助!

0 个答案:

没有答案