我似乎遇到了几行代码的问题,因为它在xampp上的本地服务器上工作,但是当我通过FTP上传到我的域时,它不再作品。我附上了代码片段以及它包含的文件。域名所做的只是完全忽视了代码,并继续进行,就好像它不在那里一样。任何帮助提前非常感谢!PHP代码在本地服务器上工作,但在域上不工作
代码片段
<?php
include_once("colors.inc.php");
$ex=new GetMostCommonColors();
$ex->image="http://maps.googleapis.com/maps/api/staticmap?center=25.437484181498,-89.594942854837&zoom=50&size=600x300&maptype=roadmap&markers=color:blue&sensor=false";
$colors=$ex->Get_Color();
$how_many=12;
$colors_key=array_keys($colors);
?>
colors.inc.php
<?php
class GetMostCommonColors
{
var $image;
function Get_Color()
{
if (isset($this->image))
{
$PREVIEW_WIDTH = 150;/
$PREVIEW_HEIGHT = 150;
$size = GetImageSize($this->image);
$scale=1;
if ($size[0]>0)
$scale = min($PREVIEW_WIDTH/$size[0], $PREVIEW_HEIGHT/$size[1]);
if ($scale < 1)
{
$width = floor($scale*$size[0]);
$height = floor($scale*$size[1]);
}
else
{
$width = $size[0];
$height = $size[1];
}
$image_resized = imagecreatetruecolor($width, $height);
if ($size[2]==1)
$image_orig=imagecreatefromgif($this->image);
if ($size[2]==2)
$image_orig=imagecreatefromjpeg($this->image);
if ($size[2]==3)
$image_orig=imagecreatefrompng($this->image);
imagecopyresampled($image_resized, $image_orig, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);
$im = $image_resized;
$imgWidth = imagesx($im);
$imgHeight = imagesy($im);
for ($y=0; $y < $imgHeight; $y++)
{
for ($x=0; $x < $imgWidth; $x++)
{
$index = imagecolorat($im,$x,$y);
$Colors = imagecolorsforindex($im,$index);
$Colors['red']=intval((($Colors['red'])+15)/32)*32;
$Colors['green']=intval((($Colors['green'])+15)/32)*32;
$Colors['blue']=intval((($Colors['blue'])+15)/32)*32;
if ($Colors['red']>=256)
$Colors['red']=240;
if ($Colors['green']>=256)
$Colors['green']=240;
if ($Colors['blue']>=256)
$Colors['blue']=240;
$hexarray[]=substr("0".dechex($Colors['red']),-2).substr("0".dechex($Colors['green']),-2).substr("0".dechex($Colors['blue']),-2);
}
}
$hexarray=array_count_values($hexarray);
natsort($hexarray);
$hexarray=array_reverse($hexarray,true);
return $hexarray;
}
else die("You must enter a filename! (\$image parameter)");
}
}
?>
你可以在实时服务器上查看源代码吗?你能看到你的PHP代码? – andrewsi
include_once(“colors.inc.php”);路径很好? – underscore
当我点击查看源代码时,没有任何php代码出现(我相信这应该会发生),但是当我查看包含代码的上传文件时,它显示出来了。再次感谢你的帮助! – user3288629