function uploadpath($f, $m = '+http') { global $iCMS; switch ($m) { case '+http': $fp = $iCMS->config['uploadURL'] . '/' . $f; break; case '-http': $fp = str_replace($iCMS->config['uploadURL'] . '/', '', $f); break; case 'http2iPATH': $f = str_replace($iCMS->config['uploadURL'] . '/', '', $f); $fp = FS::path_join(iPATH, $iCMS->config['uploadfiledir']) . '/' . $f; break; case 'iPATH2http': $f = str_replace(FS::path_join(iPATH, $iCMS->config['uploadfiledir']) . '/', '', $f); $fp = $iCMS->config['uploadURL'] . '/' . $f; break; case '+iPATH': $fp = FS::path_join(iPATH, $iCMS->config['uploadfiledir']) . '/' . $f; break; case '-iPATH': $fp = str_replace(FS::path_join(iPATH, $iCMS->config['uploadfiledir']) . '/', '', $f); break; } return $fp; }
function docrop() { //header('Content-type: image/jpeg'); $tMap = array(1 => 'gif', 2 => 'jpeg', 3 => 'png'); $pic = $_POST['pFile']; $iPic = uploadpath($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']; if ($width == $w && $height == $h) { javascript::alert('源图小于或等于剪裁尺寸,不剪裁!', 'js:parent.iCMS.insert("' . $pic . '","' . $_POST['callback'] . '");'); } if ($width == $_width && $height == $_height) { //不对源图缩放 $_img = iUpload::imagecreate($tMap[$type], $iPic); $_Type = $_img['type']; } else { $img = iUpload::imagecreate($tMap[$type], $iPic); $_Type = $img['type']; if ($img['res']) { $thumb = imagecreatetruecolor($_width, $_height); imagecopyresampled($thumb, $img['res'], 0, 0, 0, 0, $_width, $_height, $width, $height); $_tmpfile = FS::path_join(iPATH, $iCMS->config['uploadfiledir']) . '/crop_tmp_' . time() . rand(1, 999999); iUpload::image($thumb, $_Type, $_tmpfile); $_tmpfile .= '.' . $_Type; $_img = iUpload::imagecreate($tMap[$type], $_tmpfile); FS::del($_tmpfile); } } if ($_img['res']) { $_thumb = imagecreatetruecolor($w, $h); imagecopyresampled($_thumb, $_img['res'], 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; FS::mkdir($thumbpath); iUpload::image($_thumb, $_img['type'], $fileName); $fileName .= '.' . $_Type; javascript::dialog($pic . '<br />剪裁成功!', 'js:parent.iCMS.insert("' . uploadpath($fileName, '-iPATH') . '","' . $_POST['callback'] . '");parent.iCMS_WINDOW_' . iCMSKEY . '.close();'); } }
function FILES($field, $intro = "", $_dir = "", $FileName = "", $type = "upload") { global $iCMS; $RootPath = FS::path_join(iPATH, $iCMS->config['uploadfiledir']) . '/'; //绝对路径 if ($_FILES[$field]['name']) { $tmp_name = $_FILES[$field]['tmp_name']; !is_uploaded_file($tmp_name) && exit("What are you doing?"); if ($_FILES[$field]['error'] > 0) { switch ((int) $_FILES[$field]['error']) { case UPLOAD_ERR_NO_FILE: @unlink($tmp_name); javascript::alert('请选择上传文件!'); return false; break; case UPLOAD_ERR_FORM_SIZE: @unlink($tmp_name); javascript::alert('上传的文件超过大小!'); return false; break; } return false; } $_FileSize = @filesize($tmp_name); //文件类型 $oFileName = $_FILES[$field]['name']; // preg_match("/\.([a-zA-Z0-9]{2,4})$/",$oFileName,$exts); $FileExt = strtolower(FS::getExt($oFileName)); //ļʽ self::CheckValidExt($oFileName); //判断文件类型 //过滤文件; strstr($FileExt, 'ph') && ($FileExt = "phpfile"); in_array($FileExt, array('cer', 'htr', 'cdx', 'asa', 'asp', 'jsp', 'aspx', 'cgi')) && ($FileExt .= "file"); $FileMd5 = md5_file($tmp_name); $rs = iCMS_DB::getRow("SELECT * FROM #iCMS@__file WHERE `filename`='{$FileMd5}' LIMIT 1"); if (empty($rs) || $type == "reupload") { empty($FileName) && ($FileName = $FileMd5 . "." . $FileExt); // 文件保存目录方式 $FileDir = ""; if (empty($_dir)) { 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']); } } else { $FileDir = $_dir; } $RootPath = $RootPath . $FileDir . '/'; //创建目录 FS::mkdir($RootPath); //文件名 $FilePath = $FileDir . '/' . $FileName; $FileRootPath = $RootPath . $FileName; self::saveUpload($tmp_name, $FileRootPath); if (in_array($FileExt, array('gif', 'jpg', 'jpeg', 'png'))) { if ($iCMS->config['isthumb'] && ($iCMS->config['thumbwidth'] || $iCMS->config['thumbhight'])) { FS::mkdir($RootPath . "thumb"); $Thumb = self::thumbnail($RootPath, $FileRootPath, $FileMd5); !empty($Thumb['src']) && $iCMS->config['thumbwatermark'] && self::watermark($Thumb['src']); } self::watermark($FileRootPath); } // 写入数据库 empty($_FileSize) && ($_FileSize = 0); if ($type == "upload") { iCMS_DB::query("INSERT INTO `#iCMS@__file` (`filename`,`ofilename`,`path`,`intro`,`ext`,`size`,`time`,`type`) VALUES ('{$FileMd5}', '{$oFileName}', '{$FileDir}','{$intro}', '{$FileExt}', '{$_FileSize}', '" . time() . "', '0') "); $fid = iCMS_DB::$insert_id; } } else { $fid = $rs->id; $FilePath = $rs->path . "/" . $rs->filename . "." . $rs->ext; $FileName = $rs->filename . "." . $rs->ext; unlink($tmp_name); } return array('fid' => $fid, 'FilePath' => $FilePath, 'OriginalFileName' => $oFileName, 'FileName' => $FileName); } else { return; } }
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();'); } }