我正在尝试在用户个人资料页面中显示用户上传的图像。图片上传成功,但显示时显示此错误:“图片无法显示,因为它包含错误”。
我的上传代码是:
<?php
session_start();
require_once("config.php");
header ("Content-type: image/jpg" );
if ( $_GET["id"] != "" )
{
if ( file_exists ( "media/userphotos/".$_GET["id"].".jpg" ) )
$imageToShow = SITEURL."media/userphotos/".$_GET["id"].".jpg";
else
{
$imgNumber = rand ( 1, 5 );
$imageToShow = SITEURL."images/nimg$imgNumber.jpg";
}
}
if ( strchr ( $imageToShow , ".gif" ) )
$image = imagecreatefromgif ( $imageToShow );
else
$image = imagecreatefromjpeg ( $imageToShow );
list ( $width, $height ) = getimagesize ( $imageToShow );
$diffWidth = 1;
$diffHeight = 1;
if ( $width > $height )
{
if ( $width > 130 )
{
$diffWidth = 1 - ( ( $width-130 ) / $width ) ;
$diffHeight = $diffWidth ;
}
}
else
{
if ( $height > 110 )
{
$diffHeight = 1 - ( ( $height-110 ) / $height ) ;
$diffWidth = $diffHeight ;
}
}
$modwidth = $width * $diffWidth ;
$modheight = $height * $diffHeight ;
//$modwidth = 130 ;
//$modheight = 110 ;
// Resizing the Image
$tn = imagecreatetruecolor ( $modwidth, $modheight ) ;
imagecopyresampled ( $tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height ) ;
/******** this line outputs image as thumbnail or not ( conditioned ) *********/
if ( $tn )
imagejpeg( $tn , "" , 99 ) ;
else
imagejpeg( $image , "" , 99 ) ;
imagedestroy ( $image ) ;
?>
要显示我使用的图像:
<img src="<?php echo SITEURL."userimage.php?id=".$userDetails["UserID"] ?>" style="width:120px; padding:2px; border:#999999 1px solid;" />
谁能解释为什么图像不会显示?