У меня очень неприятная проблема с моим PHP-скриптом ниже. Все работает, как и ожидалось, на моей локальной машине с использованием XAMPP, но когда я помещаю его в Интернет, я получаю:
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /homepages/38/d220091779/htdocs/roughgiraffed/RG2/portfolio_item_vars.php on line 20
Я был бы очень признателен, если бы кто-нибудь взглянул на меня или дал совет.
Ошибка в строке прямо под array_push($projectImages, $filePath);
в нижней части функции.
РЕДАКТИРОВАТЬ: несмотря на то, что ошибка указана в строке 20 (в getImages ()), я удалил класс ниже и ошибка исчезла. Конечно, я все еще хочу, чтобы класс работал ... но значит ли это, что это проблема с моей версией php?
<?php
$pageTitle = "Portfolio";
//return an array of the (non-featured, non-thumb) images within a given project
function getImages($category, $project){
$projectImages = Array();
if ($dir = opendir("portfolio/" . $category . "/" . $project . "/")){
//open each 'file' in the directory
while($file = readdir($dir)){
$filePath = "portfolio/" . $category.'/'.$project.'/'.$file;
//check if it really is a file
if($file != "." && $file != ".." && $file[0] != '.' && is_file($filePath)) {
//check if it is an image
if(getimagesize($filePath)){
//ignore featured_image and _thumbs
if(!strstr($file, "featured_image") && !strstr($file, "_thumb")){
//Add the non-featured, non-thumb image to the array
array_push($projectImages, $filePath);
}
}
}
}
closedir($dir);
}
return $projectImages;
}
class ImgResizer {
private $originalFile = '';
public function __construct($originalFile = '') {
$this -> originalFile = $originalFile;
}
public function resize($newWidth, $targetFile) {
if (empty($newWidth) || empty($targetFile)) {
return false;
}
$src = imagecreatefromjpeg($this -> originalFile);
list($width, $height) = getimagesize($this -> originalFile);
$newHeight = ($height / $width) * $newWidth;
$tmp = imagecreatetruecolor($newWidth, $newHeight);
imagecopyresampled($tmp, $src, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
if (file_exists($targetFile)) {
unlink($targetFile);
}
imagejpeg($tmp, $targetFile, 85); // 85 is my choice, make it between 0 – 100 for output image quality with 100 being the most luxurious
}
}
?>
Мой Localhost работает под управлением PHP версии 5.3.1
WebHost работает под управлением PHP версии 4.4.9