win7任务栏缩略图 图片上传制作缩略图--类似手机相册

WBOY
Lepaskan: 2016-07-28 08:30:14
asal
923 orang telah melayarinya
function uploadPic(){
	$back_code = array();
	$upTypes = array(
			'image/jpg',
			'image/jpeg',
			'image/png',
			'image/gif',
			'image/bmp',
	);
	$temp = array(1=>'gif', 2=>'jpeg', 3=>'png');
	$max_file_size = 10000000; // 文件大小限制
	$upload_dir = "/var/www/html/dove.kmapp.cn/Upload/WeddingSpace/"; // 上传路径
	$date_dir = date("Y-m-d",time()); // 按日期分目录存储
	$update_time = date("Y-m-d H:i:s",time()); // 按日期分目录存储
	$conn = connect_to_db();

	// 判断文件类型和文件大小
	if(in_array($_FILES['file']['type'], $upTypes) && $_FILES['file']['size']  0){
			$back_code['num'] = -2;
			$back_code['msg'] =  $_FILES["file"]["error"] ;
		}else{

			// 获取手机照片的旋转角信息  1:0°,6:顺90°,8:逆90°,3:180°
			$exif_arr = exif_read_data($_FILES['file']['tmp_name'], 'IFD0');
			$Orientation = $exif_arr['Orientation'];
			if($Orientation == 1){
				$degrees = 0;
			}else if($Orientation == 6){
				$degrees = 270;
			}else if($Orientation == 8){
				$degrees = 90;
			}else if($Orientation == 3){
				$degrees = 180;
			}

			$photo_postfix = explode('/', $_FILES['file']['type'])[1];
			$randStrArr = getUrl();
			$photo_name = $randStrArr['randStr'] . $randStrArr['timeStr'] . '.' . $photo_postfix; // 文件名
			$thumb_name = 'thumb_' . $photo_name ;
			$photo_url = $date_dir . '/' . $photo_name;
			$thumb_url = $date_dir . '/' . 'thumb_' . $photo_name ;
			// 判断是否存在目录并创建
			if(!is_dir($upload_dir . $date_dir)){
				mkdir($upload_dir . $date_dir);
			}

			// 制作缩略图 *****
			$size_wh = getimagesize($_FILES['file']['tmp_name']);//{0: 1280, 1: 800, 2: 2, 3: "width="1280" height="800"", bits: 8, channels: 3, mime: "image/jpeg"}
			$thumb_width = 300;
			$thumb_height = 300;
			$size_width = $size_wh[0]; // 宽
			$size_height = $size_wh[1]; // 高
			$img_type = $size_wh[2]; // 文件类型

	 		$create_name = 'imagecreatefrom'. $temp[$img_type];
	 		$output_name = 'image' . $temp[$img_type];
	        // $cimg = imagecreatetruecolor($thumb, $thumb);
	        $timg = imagecreatetruecolor(300,300);
	        $source = $create_name($_FILES['file']['tmp_name']);

	        $ratio_w=1.0 * $thumb_width / $size_width;  
			$ratio_h=1.0 * $thumb_height / $size_height;  
			$ratio=1.0; 

			if( ($ratio_w  1 && $ratio_h > 1)){  
				$ratio = $ratio_w  $thumb_width){
	        // 	$new_height = 0;
	        // 	$new_width = 
	        // }
	        // imagecopyresampled($cimg, $source, 0,0, 0,0, $thumb,$thumb, $size_width,$size_height);
	        // imagecopyresampled($timg, $cimg, 0,0, 0,0, 120,120, $thumb,$thumb);
	        // imagecopyresampled($timg, $source, 0,0, $tw,$th, 240,240, $size_width,$size_height);

	        $rotate = imagerotate($timg, $degrees, 0);

	        if($output_name($rotate , $upload_dir . $date_dir . '/' . $thumb_name , 100)){
	        	// 上传文件
				if(move_uploaded_file($_FILES['file']['tmp_name'], $upload_dir . $date_dir . '/' . $photo_name)){
					$insert_sql = "INSERT INTO `wedding_space_photo` (openid,wedding_ID,big_photo,small_photo,update_time) VALUES ('$openid','$wedding_ID','$photo_url','$thumb_url','$update_time') ";
					mysql_query($insert_sql);
					$id = mysql_insert_id();
					$back_code['num'] = 0;
					$back_code['msg'] = "上传成功";
					$back_code['img_id'] = $id;
					$back_code['src'] = "http://dove.kmapp.cn/Upload/WeddingSpace/".$date_dir. '/' .$photo_name;
					$back_code['thumb_src'] = "http://dove.kmapp.cn/Upload/WeddingSpace/".$date_dir. '/' .$thumb_name;
				}else{
					$back_code['num'] = -4;
					$back_code['msg'] = "上传失败,请重试";
				}
	        }else{
				$back_code['num'] = -5;
				$back_code['msg'] = "做略图制作失败,请重试";
			}				
			
		}
	}else{
		$back_code['num'] = -3;
		$back_code['msg'] = "上传文件非法";
	}
	return $back_code;
}
Salin selepas log masuk

以上就介绍了win7任务栏缩略图 图片上传制作缩略图--类似手机相册,包括了win7任务栏缩略图方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan