1、先创建的一个简单的上传页面upload.php。先通过前端代码压缩图片,直接上代码
实名验证 营业执照:2、前端图片压缩后,请求到自定义的接口upload_deal.php.代码如下 '', 'status'=>'error', 'img_url'=>'' ); if(!is_dir($folder)) { if(!mkdir($folder, 0777, true)){ $out['msg'] = '图片目录创建失败!'; echo json_encode($out); exit; } } $im = $_FILES[$filename]['tmp_name']; //上传图片资源 $maxwidth="1056"; //设置图片的最大宽度 $maxheight="500"; //设置图片的最大高度 $imgname = $folder.$newName; //图片存放路径 根据自己图片路径而定 $filetype=$_FILES[$filename]['type'];//图片类型 $result = thumbImage($im,$maxwidth,$maxheight,$imgname,$filetype); if($result){ $out['msg'] = '图片上传成功'; $out['status'] = 'success'; $out['img_url'] = $folder.$newName; }else{ $out['msg'] = '图片上传失败'; } return json_encode($out); exit; } //压缩图片 function thumbImage($im,$maxwidth,$maxheight,$name,$filetype) { switch ($filetype) { case 'image/pjpeg': case 'image/jpeg': $im = imagecreatefromjpeg($im); //PHP图片处理系统函数 break; case 'image/gif': $im = imagecreatefromgif($im); break; case 'image/png': $im = imagecreatefrompng($im); break; case 'image/wbmp': $im = imagecreatefromwbmp($im); break; } $resizewidth_tag = $resizeheight_tag = false; $pic_width = imagesx($im); $pic_height = imagesy($im); if(($maxwidth && $pic_width > $maxwidth) || ($maxheight && $pic_height > $maxheight)) { $resizewidth_tag = $resizeheight_tag = false; if($maxwidth && $pic_width>$maxwidth) { $widthratio = $maxwidth / $pic_width; $resizewidth_tag = true; } if($maxheight && $pic_height>$maxheight) { $heightratio = $maxheight / $pic_height; $resizeheight_tag = true; } if($resizewidth_tag && $resizeheight_tag) { if($widthratio < $heightratio) $ratio = $widthratio; else $ratio = $heightratio; } if($resizewidth_tag && !$resizeheight_tag) $ratio = $widthratio; if($resizeheight_tag && !$resizewidth_tag) $ratio = $heightratio; $newwidth = $pic_width * $ratio; $newheight = $pic_height * $ratio; if(function_exists("imagecopyresampled")) { $newim = imagecreatetruecolor($newwidth,$newheight);//PHP图片处理系统函数 imagecopyresampled($newim,$im,0,0,0,0,$newwidth,$newheight,$pic_width,$pic_height);//PHP图片处理系统函数 } else { $newim = imagecreate($newwidth,$newheight); imagecopyresized($newim,$im,0,0,0,0,$newwidth,$newheight,$pic_width,$pic_height); } switch ($filetype) { case 'image/pjpeg' : case 'image/jpeg' : $result = imagejpeg($newim,$name); break; case 'image/gif' : $result = imagegif($newim,$name); break; case 'image/png' : $result = imagepng($newim,$name); break; case 'image/wbmp' : $result = imagewbmp($newim,$name); break; } imagedestroy($newim); } else { switch ($filetype) { case 'image/pjpeg' : case 'image/jpeg' : $result = imagejpeg($im,$name); break; case 'image/gif' : $result = imagegif($im,$name); break; case 'image/png' : $result = imagepng($im,$name); break; case 'image/wbmp' : $result = imagewbmp($im,$name); break; } } return $result; }
门店照:
" maxlength="15"> " maxlength="15">
一、phpStudy,是一个新手入门最常用的开发环境。二、WampServer,WampServer也同样的也是和phpStudy一样操作简单对小白比较友好。三、XAMPP,XAMPP(Apache+MySQL+PHP+PERL)是一个功能强大的建站集成软件包;四、MAMP,MAMP分为两种MAMP和MAMP Pro for Mac。五、宝塔面板,宝塔面板是一款服务器管理软件,支持windows和linux系统。六、UPUPW,UPUPW是目前Windows平台下最具特色的Web服务器PHP套件。