我想调整大小并上传PHP中的图像,但图像没有上传

时间:2015-12-11 08:17:34

标签: php php-gd

我想在PHP中调整大小并上传图片,但图片不会使用以下代码上传。我哪里错了?

public function category()
{
    $picture = $_FILES ['image'] ['name'];
    header('Content-type: image/JPG');
    $myimage = resizeImage($picture, '190', '80');
    $filename = $picture;
    $newwidth = $_POST ['width'];
    $newheight = $_POST ['height'];
    list ($width, $height) = getimagesize($picture);
    if ($width > $height && $newheight < $height) {
        $newheight = $height / ($width / $newwidth);
    } else if ($width < $height && $newwidth < $width) {
        $newwidth = $width / ($height / $newheight);
    } else {
        $newwidth = $width;
        $newheight = $height;
    }
    $thumb = imagecreatetruecolor($newwidth, $newheight);
    $source = imagecreatefromjpeg($filename);
    imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
    $result = move_uploaded_file($source, "images/" . $filename);
    if ($result) {
        $responseJSON = array("Status" => "True", "Message" => "image uploaded successfully");
        $response = json_encode($responseJSON);
        echo $response;
    }
}

1 个答案:

答案 0 :(得分:0)

我认为

$source = imagecreatefromjpeg($filename);

应该是

 $truefile=$_FILES ['image'] ['tmp_name'];
$source = imagecreatefromjpeg($truefile);

尝试发布你的答案