function domanage() { if ($_FILES['Filedata']) { require_once iPATH . 'include/upload.class.php'; $this->iCMS->config['iswatermark'] = false; $this->iCMS->config['isthumb'] = false; $ext = FS::getExt($_FILES['Filedata']['name']); $F = iUpload::FILES("Filedata", 0, '', 'avatar', 'tmp_' . member::$uId . '.' . strtolower($ext), 'avatar'); // echo FS::fp($F["FilePath"],'+http'); echo '../' . $this->iCMS->config['uploadfiledir'] . '/' . $F["FilePath"]; } else { $_dir = ceil(member::$uId / 500); $data = file_get_contents("php://input"); $length = strlen($data); $lastIndex = 0; $sizeIndex = 0; $sizeArray = array(120, 48, 24); //同时上传3个尺寸的头像。 分割数据 while ($lastIndex < $length) { $a = unpack('L', $data[$lastIndex + 3] . $data[$lastIndex + 2] . $data[$lastIndex + 1] . $data[$lastIndex]); $lastIndex += 4; $avatarData = substr($data, $lastIndex, $a[1]); $lastIndex += $a[1]; $avatar = 'avatar/' . $_dir . '/' . member::$uId . '_' . $sizeArray[$sizeIndex] . '.gif'; $fp = FS::fp($avatar, '+iPATH'); @FS::mkdir(dirname($fp)); @FS::write($fp, $avatarData); $sizeIndex++; } $rootpf = FS::fp('avatar/tmp_' . member::$uId, '+iPATH'); foreach (glob($rootpf . "*") as $_fp) { file_exists($_fp) && FS::del($_fp); } } }
function docrop() { $pic = $_POST['pFile']; $iPic = FS::fp($pic, '+iPATH'); list($width, $height, $type) = @getimagesize($iPic); $_width = $_POST['width']; $_height = $_POST['height']; $w = $_POST['w']; $h = $_POST['h']; $x = $_POST['x']; $y = $_POST['y']; $ext = FS::getExt($pic); if ($width == $w && $height == $h) { javascript::alert('源图小于或等于剪裁尺寸,不剪裁!', 'js:parent.iCMS.insert("' . $pic . '","' . $_POST['callback'] . '");'); } $imgres = iUpload::imagecreate($type, $iPic); if ($width != $_width || $height != $_height) { //对源图缩放 $thumb = imagecreatetruecolor($_width, $_height); imagecopyresampled($thumb, $imgres, 0, 0, 0, 0, $_width, $_height, $width, $height); $_tmpfile = FS::path_join(iPATH, $this->iCMS->config['uploadfiledir']) . '/crop_tmp_' . time() . rand(1, 999999) . '.' . $ext; iUpload::image($thumb, $type, $_tmpfile); $imgres = iUpload::imagecreate($type, $_tmpfile); FS::del($_tmpfile); } if ($imgres) { $_thumb = imagecreatetruecolor($w, $h); imagecopyresampled($_thumb, $imgres, 0, 0, $x, $y, $w, $h, $w, $h); $thumbpath = substr($iPic, 0, strrpos($iPic, '/')) . "/thumb"; $picName = substr($iPic, 0, strrpos($iPic, '.')); $picName = substr($picName, strrpos($picName, '/')); $fileName = $thumbpath . $picName . '_' . $w . 'x' . $h . '.' . $ext; FS::mkdir($thumbpath); iUpload::image($_thumb, $type, $fileName); javascript::dialog($pic . '<br />剪裁成功!', 'js:parent.iCMS.insert("' . FS::fp($fileName, '-iPATH') . '","' . $_POST['callback'] . '");parent.iCMS_WINDOW_' . iCMSKEY . '.close();'); } }
function CheckValidExt($value) { global $iCMS; $FileExt = strtolower(FS::getExt($value)); $aExt = explode(',', strtoupper($iCMS->config['fileext'])); if (!in_array(strtoupper($FileExt), $aExt)) { javascript::alert('[' . $value . '] 不支持上传此类扩展名的附件'); } }
function remotepic(&$content, $intro = '', $autopic = false) { global $iCMS; $content = stripslashes($content); $img = array(); preg_match_all("/<img.*?src\\s*=[\"|'|\\s]*((http|file):\\/\\/.*?\\.(gif|jpg|jpeg|bmp|png)).*?>/is", $content, $match); $_array = (array) array_unique($match[1]); $uri = parse_url($iCMS->config['uploadURL']); foreach ($_array as $_k => $imgurl) { if (strstr(strtolower($imgurl), $uri['host'])) { unset($_array[$_k]); } } if (empty($_array)) { $content = addslashes($content); return; } set_time_limit(0); $RootPath = self::path_join(iPATH, $iCMS->config['uploadfiledir']) . '/'; //绝对路径 $FileDir = ""; if ($iCMS->config['savedir']) { $FileDir = str_replace(array('Y', 'y', 'm', 'n', 'd', 'j', 'H', 'EXT'), array(get_date('', 'Y'), get_date('', 'y'), get_date('', 'm'), get_date('', 'n'), get_date('', 'd'), get_date('', 'j'), get_date('', 'H'), $FileExt), $iCMS->config['savedir']); } $RootPath = $RootPath . $FileDir . "/"; $milliSecond = 'remote_' . get_date('', "YmdHis") . rand(1, 99999); self::mkdir($RootPath); require_once iPATH . 'include/snoopy.class.php'; require_once iPATH . 'include/upload.class.php'; $Snoopy = new Snoopy(); $Snoopy->agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5"; $Snoopy->accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; foreach ($_array as $key => $value) { $FileExt = strtolower(FS::getExt($value)); //ļʽ iUpload::CheckValidExt($value); //判断文件类型 //过滤文件; strstr($FileExt, 'ph') && ($FileExt = "phpfile"); in_array($FileExt, array('cer', 'htr', 'cdx', 'asa', 'asp', 'jsp', 'aspx', 'cgi')) && ($FileExt .= "file"); $FileRootPathTmp = $RootPath . $milliSecond . $key . "." . $FileExt; $Snoopy->fetch($value); if ($Snoopy->results) { self::write($FileRootPathTmp, $Snoopy->results); $FileMd5 = md5_file($FileRootPathTmp); $rs = iCMS_DB::getRow("SELECT * FROM #iCMS@__file WHERE `filename`='{$FileMd5}' LIMIT 1"); if (empty($rs)) { $FileName = $FileMd5 . "." . $FileExt; $FilePath = $FileDir . "/" . $FileName; $FileRootPath = $RootPath . $FileName; rename($FileRootPathTmp, $FileRootPath); if (in_array($FileExt, array('gif', 'jpg', 'jpeg', 'png'))) { if ($iCMS->config['isthumb'] && ($iCMS->config['thumbwidth'] || $iCMS->config['thumbhight'])) { list($width, $height, $imagetype) = getimagesize($FileRootPath); if ($width > $iCMS->config['thumbwidth'] || $height > $iCMS->config['thumbhight']) { self::mkdir($RootPath . "thumb"); } $Thumbnail = iUpload::thumbnail($RootPath, $FileRootPath, $FileMd5); !empty($Thumbnail['filepath']) && $iCMS->config['thumbwatermark'] && iUpload::watermark($Thumbnail['filepath']); } iUpload::watermark($FileRootPath); } $_FileSize = @filesize($FileRootPath); empty($_FileSize) && ($_FileSize = 0); iCMS_DB::query("INSERT INTO `#iCMS@__file` (`filename`,`ofilename`,`path`,`intro`,`ext`,`size` ,`time`,`type`) VALUES ('{$FileMd5}', '{$value}', '{$FileDir}','{$intro}', '{$FileExt}', '{$_FileSize}', '" . time() . "', '1') "); } else { $FilePath = $rs->path . "/" . $rs->filename . "." . $rs->ext; self::del($FileRootPathTmp); } $content = str_replace($value, self::fp($FilePath, '+http'), $content); if ($autopic && $key == 0) { break; } } } $content = addslashes($content); }