我的任何php脚本都无法在本地服务器“ VertrigoServ”上正确解析,该服务器是运行php7的Apache2。
我关注了一个话题 “未执行PHP代码,而是在页面上显示了代码”,并按照添加到'httpd.conf'中的说明进行操作:
LoadModule php7_module "VertrigoServ/php/php7apache2_.dll"
AddHandler application/x-httpd-php .php
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
'VertrigoServ'是本地主机的名称,'Apache'和'php'文件夹都在文件结构的此级别上,'httpd.conf'在'Apache'中的'conf'文件夹中。我是否具有“ php7apache2_.dll”的正确路径?
此外,在文档末尾:
# PHP
AddType application/x-httpd-php .php .phtml .php5 .php7
AddType application/x-httpd-php-source .phps
# PHP 7 specific configuration
<IfModule php7_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
</IfModule>
当我在我的网站上对其进行测试时,也会出现相同的问题。这是html中的代码:
<div>
<div id="lfront"></div>
<div id="lback"></div>
<!-- [THE GALLERY] -->
<div id="gallery"><?php
foreach ($images as $i) {
printf("<img src='Images/Gallery/Newspapers/thumbnail/%s' onclick='gallery.show(this)'/>", basename($i));
}
?></div>
</div>
<div>
<div id="lfront"></div>
<div id="lback"></div>
<!-- [THE GALLERY] -->
<div id="gallery"><?php
foreach ($images as $i) {
printf("<img src='Images/Gallery/Newspapers/thumbnail/%s' onclick='gallery.show(this)'/>", basename($i));
}
?></div>
</div>
这是缩略图生成器的代码,该代码位于单独的文件中;
<?php
// INIT
// INIT
$dir = __DIR__ . DIRECTORY_SEPARATOR . "Images/Gallery/Newspapers" . DIRECTORY_SEPARATOR;
$tdir = __DIR__ . DIRECTORY_SEPARATOR . "Images/Gallery/Newspapers/thumbnail" . DIRECTORY_SEPARATOR;
$maxLong = 600; // maximum width or height, whichever is longer
$quality = 40;
$images = [];
// READ FILES FROM GALLERY FOLDER
$files = glob($dir . "*.{jpg,jpeg,gif,png}", GLOB_BRACE);
// CHECK AND GENERATE THUMBNAILS
foreach ($files as $f) {
$img = basename($f);
$images[] = $img;
if (!file_exists($tdir . $img)) {
list ($width, $height) = getimagesize($dir . $img);
$ratio = $width > $height ? $maxLong / $width : $maxLong / $height ;
$newWidth = ceil($width * $ratio);
$newHeight = ceil($height * $ratio);
$source = imagecreatefromjpeg($dir . $img);
$destination = imagecreatetruecolor($newWidth, $newHeight);
imagecopyresampled($destination, $source, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
imagejpeg($destination, $tdir . $img, $quality);
}
}
我有点停滞不前,我要做的就是加载图像文件夹的内容。我希望输出加载并显示指定文件夹中的图像,但会返回;
“,basename($ i));}?>