function uploadfile($field, $intro = "", $SaveDir = "", $SaveFileName = "", $type = "upload") { global $iCMS; $UploadDir = $iCMS->config['uploadfiledir'] . "/"; $RelativePath = $iCMS->dir . $UploadDir; //相对路径 $RootPath = iPATH . $UploadDir; //绝对路径 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); alert('请选择上传文件!'); return false; break; case UPLOAD_ERR_FORM_SIZE: @unlink($tmp_name); alert('上传的文件超过大小!'); return false; break; } return false; } $_FileSize = @filesize($tmp_name); //文件类型 preg_match("/\\.([a-zA-Z0-9]{2,4})\$/", $_FILES[$field]['name'], $exts); $FileExt = strtolower($exts[1]); //ļʽ CheckValidExt($FileExt); //判断文件类型 //过滤文件; strstr($FileExt, 'ph') && ($FileExt = "phpfile"); in_array($FileExt, array('cer', 'htr', 'cdx', 'asa', 'asp', 'jsp', 'aspx', 'cgi')) && ($FileExt .= "file"); $FileNameTmp = get_date('', "YmdHis") . rand(1, 999999); empty($SaveFileName) && ($SaveFileName = $FileNameTmp . "." . $FileExt); $oFileName = $_FILES[$field]['name']; // 文件保存目录方式 $_CreateDir = ""; if (empty($SaveDir)) { if ($iCMS->config['savedir']) { $_CreateDir = str_replace(array('Y', 'y', 'm', 'n', 'd', 'j', 'EXT'), array(get_date('', 'Y'), get_date('', 'y'), get_date('', 'm'), get_date('', 'n'), get_date('', 'd'), get_date('', 'j'), $FileExt), $iCMS->config['savedir']) . "/"; } } else { $_CreateDir = $SaveDir . "/"; } // $UploadDir = $UploadDir.$_CreateDir; $RelativePath = $RelativePath . $_CreateDir; $RootPath = $RootPath . $_CreateDir; //创建目录 createdir($RootPath); //文件名 // $sFileName = $UploadDir.$SaveFileName; $RelativePath_FileName = $RelativePath . $SaveFileName; $RootPath_FileName = $RootPath . $SaveFileName; savefile($tmp_name, $RootPath_FileName); if (in_array($FileExt, array('gif', 'jpg', 'jpeg', 'png'))) { if ($iCMS->config['isthumb'] && ($iCMS->config['thumbwidth'] || $iCMS->config['thumbhight'])) { $Thumb = MakeThumbnail($RootPath, $RootPath_FileName, $FileNameTmp); !empty($Thumb['src']) && imageWaterMark($Thumb['src']); } imageWaterMark($RootPath . $SaveFileName); } $RelativePath_FileName = getfilepath($RelativePath_FileName, '', '-'); // 写入数据库 if ($type == "upload") { $iCMS->db->query("INSERT INTO `#iCMS@__file` (`filename`,`ofilename`,`path`,`intro`,`ext`,`size`,`time`,`type`) VALUES ('{$SaveFileName}', '{$oFileName}', '{$RelativePath_FileName}','{$intro}', '{$FileExt}', '{$_FileSize}', '" . time() . "', 'upload') "); } $_File = array('fid' => $iCMS->db->insert_id, 'FilePath' => $RelativePath_FileName, 'OriginalFileName' => $oFileName, 'FileName' => $SaveFileName); return $_File; } else { return; } }
function GetFileList() { $s_ReturnFlag = TrimGet("returnflag"); $s_FolderType = TrimGet("foldertype"); $s_Dir = TrimGet("dir"); $s_CurrDir = ""; $s_Dir = UTF8_to_Pagecode($s_Dir, true); switch ($s_FolderType) { case "upload": $s_CurrDir = $GLOBALS["sUploadDir"]; break; case "shareimage": $GLOBALS["sAllowExt"] = ""; $s_CurrDir = $GLOBALS["sPathShareImage"]; break; case "shareflash": $GLOBALS["sAllowExt"] = ""; $s_CurrDir = $GLOBALS["sPathShareFlash"]; break; case "sharemedia": $GLOBALS["sAllowExt"] = ""; $s_CurrDir = $GLOBALS["sPathShareMedia"]; break; default: $s_FolderType = "shareother"; $GLOBALS["sAllowExt"] = ""; $s_CurrDir = $GLOBALS["sPathShareOther"]; break; } $s_Dir = str_replace("\\", "/", $s_Dir); if (substr($s_Dir, 0, 1) == "/" || substr($s_Dir, 0, 1) == "." || substr($s_Dir, -1) == "." || strpos($s_Dir, "./") !== false || strpos($s_Dir, "/.") !== false || strpos($s_Dir, "//") !== false || strpos($s_Dir, "..") !== false) { $s_Dir = ""; } if ($s_Dir != "") { $ss_Dir = $s_CurrDir . Syscode2Pagecode($s_Dir, false); if (is_dir($ss_Dir)) { $s_CurrDir = $ss_Dir; } else { $s_Dir = ""; } } $s_List = ""; if (is_dir($s_CurrDir)) { if ($handle = opendir($s_CurrDir)) { while (false !== ($file = readdir($handle))) { $sFileType = filetype($s_CurrDir . $file); if ($sFileType == "file") { $oFiles[] = $file; } } } $i = -1; if (isset($oFiles)) { foreach ($oFiles as $oFile) { if (CheckValidExt($oFile)) { $i = $i + 1; $sFileName = $s_CurrDir . $oFile; $s_List = $s_List . "arr[" . $i . "]=new Array(\"" . Syscode2Pagecode($oFile, true) . "\", \"" . GetSizeUnit(filesize($sFileName)) . "\",\"" . date("Y-m-d H:i:s", filemtime($sFileName)) . "\");\n"; } } } } $s_List = "var arr = new Array();\n" . $s_List . "parent.setFileList('" . $s_ReturnFlag . "', '" . $s_FolderType . "', '" . $s_Dir . "', arr);"; return $s_List; }
function remote(&$content, $one = false) { global $DreamCMS, $title; $content = stripslashes($content); $img = array(); preg_match_all("/(src|SRC)=[\"|'| ]{0,}(http:\\/\\/(.*)\\.(gif|jpg|jpeg|bmp|png))/isU", $content, $img); $_array = array_unique($img[2]); foreach ($_array as $_k => $imgurl) { if (strstr(strtolower($imgurl), $DreamCMS->config['url'])) { unset($_array[$_k]); } } set_time_limit(0); $UploadDir = $DreamCMS->config['uploadfiledir'] . "/"; $RelativePath = $DreamCMS->dir . $UploadDir; //相对路径 $RootPath = DCPATH . $UploadDir; //绝对路径 switch ($DreamCMS->config['savedir']) { case "0": $_CreateDir = ""; break; //全部保存在一起 //全部保存在一起 case 'ym': $_CreateDir = _getdate("Ym") . "/"; break; //按年月 //按年月 case 'ymd': $_CreateDir = _getdate("Ymd") . "/"; break; //按年月日 //按年月日 case 'ext': $_CreateDir = $FileExt . "/"; break; //按文件类型 } $RelativePath = $RelativePath . $_CreateDir; $RootPath = $RootPath . $_CreateDir; $milliSecond = 'remote_' . _getdate("YmdHis") . rand(1, 99999); createdir($RootPath); foreach ($_array as $key => $value) { $value = trim($value); preg_match("/\\.([a-zA-Z0-9]{2,4})\$/", $value, $exts); $FileExt = strtolower($exts[1]); //ļʽ CheckValidExt($FileExt); //判断文件类型 //过滤文件; strstr($FileExt, 'ph') && ($FileExt = "phpfile"); in_array($FileExt, array('cer', 'htr', 'cdx', 'asa', 'asp', 'jsp', 'aspx', 'cgi')) && ($FileExt .= "file"); $sFileName = $milliSecond . $key . "." . $FileExt; $RootPath_FileName = $RootPath . $sFileName; $RelativePath_FileName = $RelativePath . $sFileName; $get_file = fopen_url($value); $get_file && writefile($RootPath_FileName, $get_file); if (in_array($FileExt, array('gif', 'jpg', 'png')) && $DreamCMS->config['isthumb'] && ($DreamCMS->config['thumbwidth'] || $DreamCMS->config['thumbhight'])) { list($width, $height, $imagetype) = GetImageSize($RootPath_FileName); if ($width > $DreamCMS->config['thumbwidth'] || $height > $DreamCMS->config['thumbhight']) { createdir($RootPath . "thumb"); } $Thumbnail = MakeThumbnail($RootPath, $RootPath_FileName, $milliSecond . $key); if (!empty($Thumbnail['filepath'])) { $SmallImagePath_FileName = str_replace($RootPath, $RelativePath, $Thumbnail['filepath']); imageWaterMark($Thumbnail['filepath']); } imageWaterMark($RootPath_FileName); } else { $SmallImagePathFile = ''; } $_FileSize = @filesize($RootPath_FileName); $RelativePath_FileName = str_replace($DreamCMS->dir . $UploadDir, $UploadDir, $RelativePath_FileName); $SmallImagePath_FileName = str_replace($DreamCMS->dir . $UploadDir, $UploadDir, $SmallImagePath_FileName); $DreamCMS->db->query("INSERT INTO `#DC@__file` (`filename`,`ofilename`,`path`,`thumbpath`,`intro`,`ext`,`size` ,`time`,`type`) VALUES ('{$sFileName}', '{$value}', '{$RelativePath_FileName}','{$SmallImagePath_FileName}', '{$title}', '{$FileExt}', '{$_FileSize}', '" . time() . "', 'remote') "); $content = str_replace($value, $DreamCMS->dir . $RelativePath_FileName, $content); if ($one && $key == 0) { break; } } $content = add_magic_quotes($content); }