显示错误的预写PHP脚本-无法找出错误存在的原因


Prewritten PHP Script Showing Errors - Cannot Figure Out Why The Error Exists

我使用的是《1st Web Magazine-Generate Thumbnail On The Fly》上的预编脚本。

我将脚本复制到了服务器上,但它给了我以下错误:Parse error: syntax error, unexpected '$ratio_orig' (T_VARIABLE) in /storage/emulated/legacy/www/jollyroger/jollyroger/img/gallery_temp/thumbnail.php on line 23

我已经检查了代码,但没有发现任何实际的错误。一切似乎都井然有序。

有人能看看这个代码,告诉我我是否忽略了什么吗?据我所知,list()函数中似乎有什么东西正在抛出变量。

这是我文件中的代码:

<?php
// thumb width
$square = 150;
$large = 200;
$small = 100;
////////////////////////////////////////////////////////////////////////////////// square
if( isset($_GET["img"]) &&  ( $_GET["type"] == "square" || $_GET["type"] == "" ) ){
// thumb size
$thumb_width = $square;
$thumb_height = $square; 
// align
$align = $_GET["align"];
// image source
$imgSrc = $_GET["img"];
$imgExt = substr($imgSrc,-3);
// image extension
if($imgExt == "jpg"){ $myImage = imagecreatefromjpeg($imgSrc); }
if($imgExt == "gif"){ $myImage = imagecreatefromgif($imgSrc); }
if($imgExt == "png"){ $myImage = imagecreatefrompng($imgSrc); }
// getting the image dimensions  
list($width_orig, $height_orig) = getimagesize($imgSrc);   
 // ratio
$ratio_orig = $width_orig/$height_orig;
// landscape or portrait?
if ($thumb_width/$thumb_height > $ratio_orig) {
$new_height = $thumb_width/$ratio_orig;
$new_width = $thumb_width;
} else {
$new_width = $thumb_height*$ratio_orig;
$new_height = $thumb_height;
}
// middle
$x_mid = $new_width/2;
$y_mid = $new_height/2;
// create new image
$process = imagecreatetruecolor(round($new_width), round($new_height)); 
imagecopyresampled($process, $myImage, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
$thumb = imagecreatetruecolor($thumb_width, $thumb_height); 
// alignment
if($align == ""){
imagecopyresampled($thumb, $process, 0, 0, ($x_mid-($thumb_width/2)), ($y_mid-($thumb_height/2)), $thumb_width, $thumb_height, $thumb_width, $thumb_height);
}
if($align == "top"){
imagecopyresampled($thumb, $process, 0, 0, ($x_mid-($thumb_width/2)), 0, $thumb_width, $thumb_height, $thumb_width, $thumb_height);
}
if($align == "bottom"){
imagecopyresampled($thumb, $process, 0, 0, ($x_mid-($thumb_width/2)), ($new_height-$thumb_height), $thumb_width, $thumb_height, $thumb_width, $thumb_height);
}
if($align == "left"){
imagecopyresampled($thumb, $process, 0, 0, 0, ($y_mid-($thumb_height/2)), $thumb_width, $thumb_height, $thumb_width, $thumb_height);
}
if($align == "right"){
imagecopyresampled($thumb, $process, 0, 0, ($new_width-$thumb_width), ($y_mid-($thumb_height/2)), $thumb_width, $thumb_height, $thumb_width, $thumb_height);
}
imagedestroy($process);
imagedestroy($myImage); 
if($imgExt == "jpg"){ imagejpeg($thumb, null, 100); }
if($imgExt == "gif"){ imagegif($thumb); }
if($imgExt == "png"){ imagepng($thumb, null, 9); }
 }
// normal
if(isset($_GET["img"]) && ($_GET["type"] == "large" || $_GET["type"] == "small" ) ){
if( $_GET["type"] == "large" ){ $thumb_width = $large; }
if( $_GET["type"] == "small" ){ $thumb_width = $small; }
// image source
$imgSrc = $_GET["img"];
$imgExt = substr($imgSrc,-3);
// image extension
if($imgExt == "jpg"){ $myImage = imagecreatefromjpeg($imgSrc); }
if($imgExt == "gif"){ $myImage = imagecreatefromgif($imgSrc); }
if($imgExt == "png"){ $myImage = imagecreatefrompng($imgSrc); }
//getting the image dimensions  
list($width_orig, $height_orig) = getimagesize($imgSrc);   
// ratio
$ratio_orig = $width_orig/$height_orig;
$thumb_height = $thumb_width/$ratio_orig;
// new dimensions
$new_width = $thumb_width;
$new_height = $thumb_height;
// middle
$x_mid = $new_width/2;
$y_mid = $new_height/2;
// create new image
$process = imagecreatetruecolor(round($new_width), round($new_height));
imagecopyresampled($process, $myImage, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
$thumb = imagecreatetruecolor($thumb_width, $thumb_height); 
imagecopyresampled($thumb, $process, 0, 0, ($x_mid-($thumb_width/2)), ($y_mid-($thumb_height/2)), $thumb_width, $thumb_height, $thumb_width, $thumb_height);
if($imgExt == "jpg"){ imagejpeg($thumb, null, 100); }
if($imgExt == "gif"){ imagegif($thumb); }
if($imgExt == "png"){ imagepng($thumb, null, 9); }
}
?>

即使我的编辑器中的这一行也被突出显示为红色,这表示一个错误,但由于变量触发了php错误,所以这个错误还没有显示在任何日志中。看这条线,我一点也看不出有什么不对。

if(isset($_GET["img"]) && ($_GET["type"] == "large" || $_GET["type"] == "small" ) ){

我直接从网站上复制了代码,所以我不知道为什么它不起作用。正如我所说,我已经看了一遍,一切似乎都很正常,所以我完全不知所措。

此外,这个脚本与我的图像文件位于同一目录中。我的测试url看起来是这样的:http://localhost:8080/jollyroger/jollyroger/img/gallery_temp/thumbnail.php?img=1959523_1501438810115481_7515978806557307096_n.jpg

我想我找到了一些东西。

你有以下线路:

list($width_orig, $height_orig) = getimagesize($imgSrc);  

这对我来说真的很奇怪。你把一个函数等同于一个可能导致下一行错误的函数。

如果这不是问题所在,那么要么您忘记了;,要么您试图在某处设置变量值之前访问该变量。

相关文章: