<?php

class attachments {
	public function crop_upload() {
		if (isset($GLOBALS["HTTP_RAW_POST_DATA"])) {
			$pic = $GLOBALS["HTTP_RAW_POST_DATA"];
			pc_base::load_sys_class('attachment','',0);
			//$module = trim($_GET['module']);
			//$catid = intval($_GET['catid']);
			
			if (isset($_GET['width']) && !empty($_GET['width'])) {
				$width = intval($_GET['width']);
			}
			if (isset($_GET['height']) && !empty($_GET['height'])) {
				$height = intval($_GET['height']);
			}			
			
			
			if (isset($_GET['file']) && !empty($_GET['file'])) {			
				global $Project;
				global $mysql;

				//存放地址
				$__IMGURL__ = str_replace( "\/" ,"/" , $Project["base"].$_GET['file'] );
				
				//保存图片
				file_put_contents($__IMGURL__, $pic);
				
				//mysql open
				reader_mysql();
				
				//写到数据库
				$sql = "update ".VI_DBMANPRE."attach set width=".$_GET["width"].",height=".$_GET["height"].",size=".filesize($__IMGURL__)." where name='".$_GET['file']."'";
				
				mysql_query($sql,$mysql);
				
				//mysql close
				reader_mysql(true);
			
			} else {
				return false;
			}
			
			/*
			
			if (isset($_GET['file']) && !empty($_GET['file'])) {
			
				//文件路径
				$file = $_GET['file'];
				
				//文件名
				$basename = basename($file);
				
				$filepath = str_replace(APP_PATH, '', dirname($file)).'/';
				
				if (strpos($basename, 'thumb_')!==false) {
					$file_arr = explode('_', $basename);
					$basename = array_pop($file_arr);
				}
				$new_file = 'thumb_'.$width.'_'.$height.'_'.$basename;
				file_put_contents(PHPCMS_PATH.$filepath.$new_file, $pic);
			} else {
				return false;
			}
			echo APP_PATH.$filepath.$new_file;
			
			*/
			
			exit;
		}
	}
}
?>