求一个可以上传图片到服务器的类,并且可以设置图片大小(php的)
1个回答
展开全部
function upload($path,$photo,$zoom=false){
$uploaddir = $path;
$piece = explode('.',$photo['name']);
$uploadfile = $uploaddir . md5($piece[0]).'.'.$piece[1];
$result = move_uploaded_file($photo['tmp_name'], $uploadfile);
if(!$result){
return false;
}
if($zoom){
list($width_orig, $height_orig) = getimagesize($uploadfile);
if ($width_orig!=61||$height_orig!=61) {
$image_p = imagecreatetruecolor(61, 61);
if($piece[1]=="jpg"||$piece[1]=="jpeg"){
$image = imagecreatefromjpeg($uploadfile);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, 61, 61, $width_orig, $height_orig);
imagejpeg($image_p,$uploadfile);
}else if($piece[1]=="gif"){
$image = imagecreatefromgif($uploadfile);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, 61, 61, $width_orig, $height_orig);
imagegif($image_p,$uploadfile);
}
}
}
return basename($uploadfile);
}
$uploaddir = $path;
$piece = explode('.',$photo['name']);
$uploadfile = $uploaddir . md5($piece[0]).'.'.$piece[1];
$result = move_uploaded_file($photo['tmp_name'], $uploadfile);
if(!$result){
return false;
}
if($zoom){
list($width_orig, $height_orig) = getimagesize($uploadfile);
if ($width_orig!=61||$height_orig!=61) {
$image_p = imagecreatetruecolor(61, 61);
if($piece[1]=="jpg"||$piece[1]=="jpeg"){
$image = imagecreatefromjpeg($uploadfile);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, 61, 61, $width_orig, $height_orig);
imagejpeg($image_p,$uploadfile);
}else if($piece[1]=="gif"){
$image = imagecreatefromgif($uploadfile);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, 61, 61, $width_orig, $height_orig);
imagegif($image_p,$uploadfile);
}
}
}
return basename($uploadfile);
}
参考资料: www.phptogether.com
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询