我有这个代码可以在我的localhost和one.com虚拟主机上运行。但是当在hostmonster.com的ftp上传时,浏览器会返回500错误。 我正在使用TWIG作为模板引擎。
以下是页面的链接:
不起作用(hostmonster.com):http://armourertech.com/produit.php
work(one.com):http://chacartz.fr/autre/armourer/produit.php
hostmonster.com的技术人员告诉我错误在第12行:
$walkdir_gearbox = new Twig_SimpleFilter ( 'walkdir_gearbox', function ($path_01)
代码:
<?php
require "twig.php";
require "nav.php";
$head_title = "armourertech";
$nav['produit'] = "actuel";
$keywords = "";
$description = "";
$robots = "index, follow";
$googlebot = "index, follow";
$walkdir_gearbox = new Twig_SimpleFilter ( 'walkdir_gearbox', function ($path_01) {//<-line 12
$path_01 = "img/x-hightech/01gearbox";
$d = new DirectoryIterator($path_01);
foreach($d as $f) {
if(
preg_match('/(\.gif|\.png|\.jpe?g)$/', $f->getFilename())
) {
list($w, $h) = getimagesize($f->getPathname());
$file = basename($f, ".jpg");
echo "<figure itemprop=\"associatedMedia\" itemscope itemtype=\"http://schema.org/ImageObject\"><a href=\"img/x-hightech/01gearbox/".$f->getFilename() . "\" itemprop=\"contentUrl\" data-size=\"".$w."x".$h."\"><img src=\"img/x-hightech/thumbs/01gearbox/".$f->getFilename() . "\" itemprop=\"thumbnail\" alt=\"".$file." - ARMOURERTECH\" /></a><figcaption itemprop=\"caption description\">".$file."</figcaption></figure>";
} elseif($f->isDir() && $f->getFilename() != '.' && $f->getFilename() != '..') {
walkdir_gearbox($f->getPathname());
}
}
});
$walkdir_gearboxcnc = new Twig_SimpleFilter ( 'walkdir_gearboxcnc', function ($path_02) {
$path_02 = "img/x-hightech/02fabrication-gearbox-cnc";
$d = new DirectoryIterator($path_02);
foreach($d as $f) {
if(
preg_match('/(\.gif|\.png|\.jpe?g)$/', $f->getFilename())
) {
list($w, $h) = getimagesize($f->getPathname());
$file = basename($f, ".jpg");
echo "<figure itemprop=\"associatedMedia\" itemscope itemtype=\"http://schema.org/ImageObject\"><a href=\"img/x-hightech/02fabrication-gearbox-cnc/".$f->getFilename() . "\" itemprop=\"contentUrl\" data-size=\"".$w."x".$h."\"><img src=\"img/x-hightech/thumbs/02fabrication-gearbox-cnc/".$f->getFilename() . "\" itemprop=\"thumbnail\" alt=\"".$file." - ARMOURERTECH\" /></a><figcaption itemprop=\"caption description\">".$file."</figcaption></figure>";
} elseif($f->isDir() && $f->getFilename() != '.' && $f->getFilename() != '..') {
walkdir_gearboxcnc($f->getPathname());
}
}
});
$walkdir_piston = new Twig_SimpleFilter ( 'walkdir_piston', function ($path_03) {
$path_03 = "img/x-hightech/03piston-gear-set";
$d = new DirectoryIterator($path_03);
foreach($d as $f) {
if(
preg_match('/(\.gif|\.png|\.jpe?g)$/', $f->getFilename())
) {
list($w, $h) = getimagesize($f->getPathname());
$file = basename($f, ".jpg");
echo "<figure itemprop=\"associatedMedia\" itemscope itemtype=\"http://schema.org/ImageObject\"><a href=\"img/x-hightech/03piston-gear-set/".$f->getFilename() . "\" itemprop=\"contentUrl\" data-size=\"".$w."x".$h."\"><img src=\"img/x-hightech/thumbs/03piston-gear-set/".$f->getFilename() . "\" itemprop=\"thumbnail\" alt=\"".$file." - ARMOURERTECH\" /></a><figcaption itemprop=\"caption description\">".$file."</figcaption></figure>";
} elseif($f->isDir() && $f->getFilename() != '.' && $f->getFilename() != '..') {
walkdir_piston($f->getPathname());
}
}
});
$walkdir_cylindre = new Twig_SimpleFilter ( 'walkdir_cylindre', function ($path_04) {
$path_04 = "img/x-hightech/04tete-cylindre";
$d = new DirectoryIterator($path_04);
foreach($d as $f) {
if(
preg_match('/(\.gif|\.png|\.jpe?g)$/', $f->getFilename())
) {
list($w, $h) = getimagesize($f->getPathname());
$file = basename($f, ".jpg");
echo "<figure itemprop=\"associatedMedia\" itemscope itemtype=\"http://schema.org/ImageObject\"><a href=\"img/x-hightech/04tete-cylindre/".$f->getFilename() . "\" itemprop=\"contentUrl\" data-size=\"".$w."x".$h."\"><img src=\"img/x-hightech/thumbs/04tete-cylindre/".$f->getFilename() . "\" itemprop=\"thumbnail\" alt=\"".$file." - ARMOURERTECH\" /></a><figcaption itemprop=\"caption description\">".$file."</figcaption></figure>";
} elseif($f->isDir() && $f->getFilename() != '.' && $f->getFilename() != '..') {
walkdir_cylindre($f->getPathname());
}
}
});
$walkdir_hopup = new Twig_SimpleFilter ( 'walkdir_hopup', function ($path_05) {
$path_05 = "img/x-hightech/05hopup";
$d = new DirectoryIterator($path_05);
foreach($d as $f) {
if(
preg_match('/(\.gif|\.png|\.jpe?g)$/', $f->getFilename())
) {
list($w, $h) = getimagesize($f->getPathname());
$file = basename($f, ".jpg");
echo "<figure itemprop=\"associatedMedia\" itemscope itemtype=\"http://schema.org/ImageObject\"><a href=\"img/x-hightech/05hopup/".$f->getFilename() . "\" itemprop=\"contentUrl\" data-size=\"".$w."x".$h."\"><img src=\"img/x-hightech/thumbs/05hopup/".$f->getFilename() . "\" itemprop=\"thumbnail\" alt=\"".$file." - ARMOURERTECH\" /></a><figcaption itemprop=\"caption description\">".$file."</figcaption></figure>";
} elseif($f->isDir() && $f->getFilename() != '.' && $f->getFilename() != '..') {
walkdir_hopup($f->getPathname());
}
}
});
$walkdir_autre = new Twig_SimpleFilter ( 'walkdir_autre', function ($path_06) {
$path_06 = "img/x-hightech/06autres";
$d = new DirectoryIterator($path_06);
foreach($d as $f) {
if(
preg_match('/(\.gif|\.png|\.jpe?g)$/', $f->getFilename())
) {
list($w, $h) = getimagesize($f->getPathname());
$file = basename($f, ".jpg");
echo "<figure itemprop=\"associatedMedia\" itemscope itemtype=\"http://schema.org/ImageObject\"><a href=\"img/x-hightech/06autres/".$f->getFilename() . "\" itemprop=\"contentUrl\" data-size=\"".$w."x".$h."\"><img src=\"img/x-hightech/thumbs/06autres/".$f->getFilename() . "\" itemprop=\"thumbnail\" alt=\"".$file." - ARMOURERTECH\" /></a><figcaption itemprop=\"caption description\">".$file."</figcaption></figure>";
} elseif($f->isDir() && $f->getFilename() != '.' && $f->getFilename() != '..') {
walkdir_autre($f->getPathname());
}
}
});
$twig = new Twig_Environment($loader);
$twig->addFilter($walkdir_gearbox);
$twig->addFilter($walkdir_gearboxcnc);
$twig->addFilter($walkdir_piston);
$twig->addFilter($walkdir_cylindre);
$twig->addFilter($walkdir_hopup);
$twig->addFilter($walkdir_autre);
echo $twig->render('produit.html', array(
'nav' => $nav,
'head_title' => $head_title,
'keywords' => $keywords,
'description' => $description,
'robots' => $robots,
'googlebot' => $googlebot
)
);
?>
然后我将这一行放在html中:
{{ 'twig' |walkdir_gearbox }}
以下是error.log文件的最后几行
[15-Dec-2015 03:15:45] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/php/54/usr/lib64/php/modules/imagick.so' - /usr/php/54/usr/lib64/php/modules/imagick.so: undefined symbol: zend_new_interned_string in Unknown on line 0
[15-Dec-2015 03:15:45] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/php/54/usr/lib64/php/modules/http.so' - /usr/php/54/usr/lib64/php/modules/http.so: undefined symbol: zend_new_interned_string in Unknown on line 0
[15-Dec-2015 03:15:45] PHP Warning: PHP Startup: magickwand: Unable to initialize module
Module compiled with module API=20100525, debug=0, thread-safety=0
PHP compiled with module API=20060613, debug=0, thread-safety=0
These options need to match
in Unknown on line 0
[15-Dec-2015 03:15:45] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/php/54/usr/lib64/php/modules/mailparse.so' - /usr/php/54/usr/lib64/php/modules/mailparse.so: undefined symbol: zend_new_interned_string in Unknown on line 0
[15-Dec-2015 03:15:45] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/php/54/usr/lib64/php/modules/oauth.so' - /usr/php/54/usr/lib64/php/modules/oauth.so: undefined symbol: zend_new_interned_string in Unknown on line 0
[15-Dec-2015 03:15:45] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/php/54/usr/lib64/php/modules/oci8.so' - /usr/php/54/usr/lib64/php/modules/oci8.so: undefined symbol: zend_new_interned_string in Unknown on line 0
[15-Dec-2015 03:15:45] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/php/54/usr/lib64/php/modules/uploadprogress.so' - /usr/php/54/usr/lib64/php/modules/uploadprogress.so: undefined symbol: zend_ini_string_ex in Unknown on line 0
[15-Dec-2015 03:15:45] PHP Parse error: syntax error, unexpected T_FUNCTION in /home8/armourer/public_html/produit.php on line 12
是否有解决方案或我被迫更换提供商?
答案 0 :(得分:0)
删除&#34;()&#34;在最后一行,它应该是:
echo $twig->render('produit.html');
另外,请检查PHP版本:仅在PHP 5.3.0及更高版本上允许使用匿名函数作为参数。