2012-09-17 106 views
0

上傳圖片在php中的最佳做法是什麼,特別是大型圖片,我可以閱讀任何網站的更多信息,使用JavaScript和jquery也會很酷。這是我目前使用的功能。圖片在php上傳

function resizeImage($image, $width, $height, $scale) { 
list($imagewidth, $imageheight, $imageType) = getimagesize($image); 
$imageType = image_type_to_mime_type($imageType); 
$newImageWidth = ceil($width * $scale); 
$newImageHeight = ceil($height * $scale); 
$newImage = imagecreatetruecolor($newImageWidth, $newImageHeight); 
switch ($imageType) { 
    case "image/gif": 
     $source = imagecreatefromgif($image); 
     break; 
    case "image/pjpeg": 
    case "image/jpeg": 
    case "image/jpg": 
     $source = imagecreatefromjpeg($image); 
     break; 
    case "image/png": 
    case "image/x-png": 
     $source = imagecreatefrompng($image); 
     break; 
} 
imagecopyresampled($newImage, $source, 0, 0, 0, 0, $newImageWidth, $newImageHeight, $width, $height); 

switch ($imageType) { 
    case "image/gif": 
     imagegif($newImage, $image); 
     break; 
    case "image/pjpeg": 
    case "image/jpeg": 
    case "image/jpg": 
     imagejpeg($newImage, $image, 90); 
     break; 
    case "image/png": 
    case "image/x-png": 
     imagepng($newImage, $image); 
     break; 
} 

chmod($image, 0777); 

}

回答

0

試試這個

http://blueimp.github.com/jQuery-File-Upload/