在php中上传图片的最佳做法是什么,尤其是大型图片,我可以阅读任何网站以获取更多相关信息,使用javascript和jquery也会很酷。这是我目前使用的功能。
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 :(得分:0)
http://www.uploadify.com/ uploadify是一个很好的jQuery插件,用于花哨的上传器。
就最佳做法而言,请始终检查MIME TYPE并尝试远离将文件和文件夹权限设置为777
http://www.bestcodingpractices.com/php_file_uploading_best_practice-11.html
答案 1 :(得分:0)
试试这个
http://blueimp.github.com/jQuery-File-Upload/
答案 2 :(得分:0)