Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
显示错误的预写PHP脚本-无法找出错误存在的原因_Php_Variables_Thumbnails - Fatal编程技术网

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

显示错误的预写PHP脚本-无法找出错误存在的原因,php,variables,thumbnails,Php,Variables,Thumbnails,我使用的是在上找到的预先编写的脚本 我将脚本复制到我的服务器上,但它给了我以下错误:Parse error:syntax error,在/storage/simulated/legacy/www/jollyroger/jollyroger/img/gallery\u temp/thumbnail.php的第23行出现意外的“$ratio\u orig”(T\u变量) 我已经检查了代码,但我无法发现任何实际错误。一切似乎都井然有序 有人能看看这个代码,告诉我我是否忽略了什么吗?从我所能收集到的信息

我使用的是在上找到的预先编写的脚本

我将脚本复制到我的服务器上,但它给了我以下错误:
Parse error:syntax error,在/storage/simulated/legacy/www/jollyroger/jollyroger/img/gallery\u temp/thumbnail.php的第23行出现意外的“$ratio\u orig”(T\u变量)

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

有人能看看这个代码,告诉我我是否忽略了什么吗?从我所能收集到的信息来看,
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($\u-GET[“img”])&&($\u-GET[“type”]=“large”|$\u-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);  
这对我来说真的很奇怪。你把一个函数等同于一个可能导致下一行错误的函数


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

您确定您使用的脚本与您在此处发布的脚本完全相同吗?我几乎敢打赌,您之前在
列表的末尾无意中删除了代码行上的分号($width\u orig,$height\u orig)=getimagesize($imgSrc)
我在这里列出的代码是从我的代码编辑器中复制的。如果我的代码中缺少它,这里也会缺少。这就是为什么我提供了到原始代码的链接。我无法发现任何差异或错误的原因。嗯,真的很奇怪。因为在你的帖子中没有空行,但是在你链接的源代码中有几行,我怀疑你您对它做了任何操作(至少删除了换行符)。因此,您可以尝试以下操作:从链接的页面再次复制并粘贴脚本,并且不做任何更改。您是否会收到相同的错误?没有更改。相同的错误。尝试将
列表()
更改为4个变量。类似于:
列表($width\u orig,$height\u orig,$type\u orig,$Attribute)
可能会将其更改为类似于
$getimagesize=getimagesize($imgSrc);list($width\u orig,$height\u orig)-$getimagesize;
?我不同意。这是list()实际工作的方式。请参阅。我同意这很奇怪,但在PHP中,事情往往很奇怪:)在这种情况下,放弃我的第一个解决方案:p