我在这里不知所措。我已经成功上传了所有内容并使用imagejpeg()
命令调整了文件的质量,但是,我的imagecopyresampled
函数似乎给了我一个错误:
警告:imagecopyresampled() 期望参数 1 是资源,第 394 行给出的字符串
$imgRaw = $_FILES[$file]['name'];
$imgRawTemp = $_FILES[$file]['tmp_name'];
$nameExtract = explode(".", $imgRaw);
$ext = $nameExtract[count($nameExtract)-1];
$imgAll = getimagesize($_FILES[$file]['tmp_name']);
$uploadedName = time().uniqid()."_original.";
$dir = "usrPld/";
$thisImg = $dir.$uploadedName.$ext;
if($imgAll['mime'] == 'image/jpeg' || $imgAll['mime'] == 'image/png')
{
if(move_uploaded_file($imgRawTemp, $thisImg))
{
list($width, $height, $type, $attr) = $imgAll;
$thumbnailWidth = 250;
$viewingWidth = 910;
$thumbHeight = $thumbnailWidth*($height/$width);
$viewingHeight = $viewingWidth*($height/$width);
if($imgAll['mime'] == 'image/jpeg')
{
$image = imagecreatefromjpeg($thisImg);
}
else if($imgAll['mime'] == 'image/png')
{
$image = imagecreatefrompng($thisImg);
}
$newName = time().uniqid().".jpg";
$newName2 = time().uniqid().".jpg";
if($width > $viewingWidth)
{
if(imagejpeg($image, $dir.$newName, 100))
{
if(imagecopyresampled($dir.$newName2,
$dir.$newName,
0, 0, 0, 0,
$viewingWidth,
$viewingHeight,
$width,
$height))
{
unlink($thisImg);
unlink($dir.$newName);
}
}
}
else
{
if(imagejpeg($image, $dir."no_".$newName, 100))
{
unlink($thisImg);
}
}
}
}
else
{
return "format error";
}
奇怪的是,我检查了$height
(因为这是错误指向的地方)并且它正在输出一个应该的数字。
我在这里先向您的帮助表示感谢。