2015-12-11 27 views
0

我想調整大小並上傳圖像在PHP中,但圖像不上傳下面的代碼。我哪裏錯了?我想調整大小並上傳一個圖像在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; 
    } 
} 
+0

你是如何調用此方法? – pavlovich

+1

你不需要使用'Imagick :: resizeImage()'而不是'resizeImage'嗎? – pavlovich

回答

0

我覺得

$source = imagecreatefromjpeg($filename); 

應該

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

嘗試張貼您的答案

相關問題