我得到了一个非常令人沮丧的问题,我的PHP脚本下面。一切正常使用XAMPP我的本地机器上如预期,但是当我把它放在网上,我得到:Php意外的T_String上php4虚拟主机,但不是在php5本地主机
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
}
}
?>
我的本地运行PHP版本5.3.1
的虚拟主机提供商运行PHP版本4.4.9
本地和Web服务器都运行相同版本的PHP吗? – Quasdunk
@Quasdunk - 对这个错误有影响吗? OP,请100000%确保您放置在网络上的文件与您在本地计算机上的文件完全相同。 – ajreal
它可能是围绕回报的parans(我非常怀疑它),试着做'return $ projectImages;'看看会有什么结果。正如Quasdunk所说,我不认为他们运行相同的版本。如果上述不起作用,请发布服务器的PHP版本。但看看这个错误,就像上传的东西似乎有些东西可能会变得混乱起来,正如阿杰莱尔所说的那样。 –