PHP 图像大小调整功能无法正常工作


PHP image resize function doesn't work properly?

我正在使用此功能调整图像大小,但它会导致错误

Call to undefined function resize()

这是我的消息来源:

$w=280;
$h=280;
resize($w,$h);
function resize($width, $height)
{
    list($w, $h) = getimagesize($_FILES['image']['tmp_name']);
    /* calculate new image size with ratio */   
    $ratio = max($width/$w, $height/$h);
    $h = ceil($height / $ratio);
    $x = ($w - $width / $ratio) / 2;
    $w = ceil($width / $ratio);
    $folder="../images/";
    /* new file name  */   
    $path = $folder.$_FILES['image']['name'];
    $update = mysql_query("update `detail` set `url` = '".$path."' where `id` = '".$id."'");
    $image = imagecreatefromstring($imgString);
    $tmp = imagecreatetruecolor($width, $height);
    imagecopyresampled($tmp, $image,0, 0,$x, 0,$width, $height,$w, $h);
    /* Save image */   
    switch ($_FILES['image']['type']) {
        case 'image/jpeg':
            imagejpeg($tmp, $path, 100);
            break;
        case 'image/png':
            imagepng($tmp, $path, 0);
            break;
        case 'image/gif':
            imagegif($tmp, $path);
            break;
        default:
            exit;
            break;
    }
    return $path;
}   

为什么我会收到此错误?

代码错误:调用未定义的函数 resize((

意味着它无权访问该功能。如果它在不同的 php 文件中,您必须首先包含它

include 'functions.inc.php';