本文整理汇总了PHP中CloseFtp函数的典型用法代码示例。如果您正苦于以下问题:PHP CloseFtp函数的具体用法?PHP CloseFtp怎么用?PHP CloseFtp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CloseFtp函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: MoveFile
/**
* 移动文件
*
* @access public
* @param string $mfile 文件
* @param string $mpath 路径
* @return string
*/
function MoveFile($mfile, $mpath)
{
if ($mpath != "" && !preg_match("#\\.\\.#", $mpath)) {
$oldfile = $this->baseDir . $this->activeDir . "/{$mfile}";
$mpath = str_replace("\\", "/", $mpath);
$mpath = preg_replace("#\\/{1,}#", "/", $mpath);
if (!preg_match("#^/#", $mpath)) {
$mpath = $this->activeDir . "/" . $mpath;
}
$truepath = $this->baseDir . $mpath;
if (is_readable($oldfile) && is_readable($truepath) && is_writable($truepath)) {
if (is_dir($truepath)) {
copy($oldfile, $truepath . "/{$mfile}");
} else {
MkdirAll($truepath, $GLOBALS['cfg_dir_purview']);
CloseFtp();
copy($oldfile, $truepath . "/{$mfile}");
}
unlink($oldfile);
ShowMsg("成功移动文件!", "file_manage_main.php?activepath={$mpath}", 0, 1000);
return 1;
} else {
ShowMsg("移动文件 {$oldfile} -> {$truepath}/{$mfile} 失败,可能是某个位置权限不足!", "file_manage_main.php?activepath={$mpath}", 0, 1000);
return 0;
}
} else {
ShowMsg("对不起,你移动的路径不合法!", "-1", 0, 5000);
return 0;
}
}
示例2: MoveFile
function MoveFile($mfile,$mpath)
{
if($mpath!="" && !ereg("\.\.",$mpath))
{
$oldfile = $this->baseDir.$this->activeDir."/$mfile";
$mpath = str_replace("\\","/",$mpath);
$mpath = ereg_replace("/{1,}","/",$mpath);
if(!ereg("^/",$mpath)){ $mpath = $this->activeDir."/".$mpath; }
$truepath = $this->baseDir.$mpath;
if(is_readable($oldfile)
&& is_readable($truepath) && is_writable($truepath))
{
if(is_dir($truepath)) copy($oldfile,$truepath."/$mfile");
else{
MkdirAll($truepath,$GLOBALS['cfg_dir_purview']);
CloseFtp();
copy($oldfile,$truepath."/$mfile");
}
unlink($oldfile);
ShowMsg("成功移动文件!","file_manage_main.php?activepath=$mpath",0,1000);
return 1;
}
else
{
ShowMsg("移动文件 $oldfile -> $truepath/$mfile 失败,可能是某个位置权限不足!","file_manage_main.php?activepath=$mpath",0,1000);
return 0;
}
}
else{
ShowMsg("对不起,你移动的路径不合法!","-1",0,5000);
return 0;
}
}
示例3: SpCreateDir
function SpCreateDir($spath,$siterefer='',$sitepath='')
{
if($spath=="") return true;
global $cfg_dir_purview,$cfg_basedir,$cfg_ftp_mkdir;
$flink = false;
if($siterefer==1) $truepath = ereg_replace("/{1,}","/",$cfg_basedir."/".$sitepath);
else if($siterefer==2){
$truepath = $sitepath;
if($cfg_isSafeMode||$cfg_ftp_mkdir=='Y'){ echo "Not Suppot Safemode !"; exit(); }
}
else $truepath = $cfg_basedir;
$spaths = explode("/",$spath);
$spath = "";
foreach($spaths as $spath){
if($spath=="") continue;
$spath = trim($spath);
$truepath .= "/".$spath;
$truepath = str_replace("\\","/",$truepath);
$truepath = ereg_replace("/{1,}","/",$truepath);
if(!is_dir($truepath) || !is_writeable($truepath)){
if(!is_dir($truepath)) $isok = MkdirAll($truepath,$GLOBALS['cfg_dir_purview']);
else $isok = ChmodAll($truepath,$GLOBALS['cfg_dir_purview']);
if(!$isok){ echo "Create dir ".$truepath." False!<br>"; CloseFtp(); return false; }
}
}
CloseFtp();
return true;
}
示例4: SpCreateDir
function SpCreateDir($spath)
{
global $cfg_dir_purview, $cfg_basedir, $cfg_ftp_mkdir, $isSafeMode;
if ($spath == '') {
return true;
}
$flink = false;
$truepath = $cfg_basedir;
$truepath = str_replace("\\", "/", $truepath);
$spaths = explode("/", $spath);
$spath = "";
foreach ($spaths as $spath) {
if ($spath == "") {
continue;
}
$spath = trim($spath);
$truepath .= "/" . $spath;
if (!is_dir($truepath) || !is_writeable($truepath)) {
if (!is_dir($truepath)) {
$isok = MkdirAll($truepath, $cfg_dir_purview);
} else {
$isok = ChmodAll($truepath, $cfg_dir_purview);
}
if (!$isok) {
echo "创建或修改目录:" . $truepath . " 失败!<br>";
CloseFtp();
return false;
}
}
}
CloseFtp();
return true;
}
示例5: GetFieldValue
function GetFieldValue($dvalue, $dtype, $aid = 0, $job = 'add', $addvar = '')
{
global $cfg_cookie_encode, $cfg_dir_purview;
if ($dtype == "int") {
$dvalue = trim(ereg_replace("[^0-9]", "", $dvalue));
if ($dvalue == "") {
$dvalue = 0;
}
return $dvalue;
} else {
if ($dtype == "float") {
$dvalue = trim(ereg_replace("[^0-9\\.]", "", $dvalue));
if ($dvalue == "") {
$dvalue = 0;
}
return $dvalue;
} else {
if ($dtype == "datetime") {
return GetMkTime($dvalue);
} else {
if ($dtype == "textdata") {
if ($job == 'edit') {
$addvarDirs = explode('/', $addvar);
$addvarDir = ereg_replace("/" . $addvarDirs[count($addvarDirs) - 1] . "\$", "", $addvar);
$mdir = $GLOBALS['cfg_basedir'] . $addvarDir;
if (!is_dir($mdir)) {
MkdirAll($mdir, $GLOBALS['cfg_dir_purview']);
}
$fp = fopen($GLOBALS['cfg_basedir'] . $addvar, "w");
fwrite($fp, stripslashes($dvalue));
fclose($fp);
CloseFtp();
return $addvar;
} else {
$ipath = $GLOBALS['cfg_cmspath'] . "/data/textdata";
$tpath = ceil($aid / 5000);
if (!is_dir($GLOBALS['cfg_basedir'] . $ipath)) {
MkdirAll($GLOBALS['cfg_basedir'] . $ipath, $cfg_dir_purview);
}
if (!is_dir($GLOBALS['cfg_basedir'] . $ipath . '/' . $tpath)) {
MkdirAll($GLOBALS['cfg_basedir'] . $ipath . '/' . $tpath, $cfg_dir_purview);
}
$ipath = $ipath . '/' . $tpath;
$filename = "{$ipath}/{$aid}-" . cn_substr(md5($cfg_cookie_encode), 0, 16) . ".txt";
$fp = fopen($GLOBALS['cfg_basedir'] . $filename, "w");
fwrite($fp, stripslashes($dvalue));
fclose($fp);
CloseFtp();
return $filename;
}
} else {
if ($dtype == "img") {
$iurl = stripslashes($dvalue);
if (trim($iurl) == "") {
return "";
}
$iurl = trim(str_replace($GLOBALS['cfg_basehost'], "", $iurl));
$imgurl = "{dede:img text='' width='' height=''} " . $iurl . " {/dede:img}";
if (eregi("^http://", $iurl) && $GLOBALS['isUrlOpen']) {
//远程图片
$reimgs = "";
if ($isUrlOpen) {
$reimgs = GetRemoteImage($iurl, $GLOBALS['adminid']);
if (is_array($reimgs)) {
$imgurl = "{dede:img text='' width='" . $reimgs[1] . "' height='" . $reimgs[2] . "'} " . $reimgs[0] . " {/dede:img}";
}
} else {
$imgurl = "{dede:img text='' width='' height=''} " . $iurl . " {/dede:img}";
}
} else {
if ($iurl != "") {
//站内图片
$imgfile = $GLOBALS['cfg_basedir'] . $iurl;
if (is_file($imgfile)) {
$imginfos = GetImageSize($imgfile, &$info);
$imgurl = "{dede:img text='' width='" . $imginfos[0] . "' height='" . $imginfos[1] . "'} {$iurl} {/dede:img}";
}
}
}
return addslashes($imgurl);
} else {
return $dvalue;
}
}
}
}
}
}
示例6: trim
$imgfile_name = trim(preg_replace("#[ \r\n\t\\*\\%\\\\/\\?><\\|\":]{1,}#", '', $imgfile_name));
if (!preg_match("#\\.(" . $cfg_imgtype . ")#i", $imgfile_name)) {
ShowMsg("你所上传的图片类型不在许可列表,请更改系统对扩展名限定的配置!", "-1");
exit;
}
$nowtme = time();
$sparr = array("image/pjpeg", "image/jpeg", "image/gif", "image/png", "image/xpng", "image/wbmp");
$imgfile_type = strtolower(trim($imgfile_type));
if (!in_array($imgfile_type, $sparr)) {
ShowMsg("上传的图片格式错误,请使用JPEG、GIF、PNG、WBMP格式的其中一种!", "-1");
exit;
}
$mdir = MyDate($cfg_addon_savetype, $nowtme);
if (!is_dir($cfg_basedir . $activepath . "/{$mdir}")) {
MkdirAll($cfg_basedir . $activepath . "/{$mdir}", $cfg_dir_purview);
CloseFtp();
}
$filename_name = $cuserLogin->getUserID() . '-' . dd2char(MyDate("ymdHis", $nowtme) . mt_rand(100, 999));
$filename = $mdir . '/' . $filename_name;
$fs = explode('.', $imgfile_name);
$filename = $filename . '.' . $fs[count($fs) - 1];
$filename_name = $filename_name . '.' . $fs[count($fs) - 1];
$fullfilename = $cfg_basedir . $activepath . "/" . $filename;
move_uploaded_file($imgfile, $fullfilename) or die("上传文件到 {$fullfilename} 失败!");
if ($cfg_remote_site == 'Y' && $remoteuploads == 1) {
//分析远程文件路径
$remotefile = str_replace(DEDEROOT, '', $fullfilename);
$localfile = '../..' . $remotefile;
//创建远程文件夹
$remotedir = preg_replace('/[^\\/]*\\.(jpg|gif|bmp|png)/', '', $remotefile);
$ftp->rmkdir($remotedir);
示例7: MemberUploads
function MemberUploads($upname, $handname, $userid = 0, $utype = 'image', $exname = '', $maxwidth = 0, $maxheight = 0, $water = false, $isadmin = false)
{
global $cfg_imgtype, $cfg_mb_addontype, $cfg_mediatype, $cfg_user_dir, $cfg_basedir, $cfg_dir_purview;
//当为游客投稿的情况下,这个 id 为 0
if (empty($userid)) {
$userid = 0;
}
if (!is_dir($cfg_basedir . $cfg_user_dir . "/{$userid}")) {
MkdirAll($cfg_basedir . $cfg_user_dir . "/{$userid}", $cfg_dir_purview);
CloseFtp();
}
//有上传文件
$allAllowType = str_replace('||', '|', $cfg_imgtype . '|' . $cfg_mediatype . '|' . $cfg_mb_addontype);
if (!empty($GLOBALS[$upname]) && is_uploaded_file($GLOBALS[$upname])) {
$nowtme = time();
$GLOBALS[$upname . '_name'] = trim(ereg_replace("[ \r\n\t\\*\\%\\/\\?><\\|\":]{1,}", '', $GLOBALS[$upname . '_name']));
//源文件类型检查
if ($utype == 'image') {
if (!eregi("\\.(" . $cfg_imgtype . ")\$", $GLOBALS[$upname . '_name'])) {
ShowMsg("你所上传的图片类型不在许可列表,请上传{$cfg_imgtype}类型!", '-1');
exit;
}
$sparr = array("image/pjpeg", "image/jpeg", "image/gif", "image/png", "image/xpng", "image/wbmp");
$imgfile_type = strtolower(trim($GLOBALS[$upname . '_type']));
if (!in_array($imgfile_type, $sparr)) {
ShowMsg('上传的图片格式错误,请使用JPEG、GIF、PNG、WBMP格式的其中一种!', '-1');
exit;
}
} else {
if ($utype == 'flash' && !eregi("\\.swf\$", $GLOBALS[$upname . '_name'])) {
ShowMsg('上传的文件必须为flash文件!', '-1');
exit;
} else {
if ($utype == 'media' && !eregi("\\.(" . $cfg_mediatype . ")\$", $GLOBALS[$upname . '_name'])) {
ShowMsg('你所上传的文件类型必须为:' . $cfg_mediatype, '-1');
exit;
} else {
if (!eregi("\\.(" . $allAllowType . ")\$", $GLOBALS[$upname . '_name'])) {
ShowMsg("你所上传的文件类型不被允许!", '-1');
exit;
}
}
}
}
//再次严格检测文件扩展名是否符合系统定义的类型
$fs = explode('.', $GLOBALS[$upname . '_name']);
$sname = $fs[count($fs) - 1];
$alltypes = explode('|', $allAllowType);
if (!in_array(strtolower($sname), $alltypes)) {
ShowMsg('你所上传的文件类型不被允许!', '-1');
exit;
}
//强制禁止的文件类型
if (eregi("\\.(asp|php|pl|cgi|shtm|js)", $sname)) {
ShowMsg('你上传的文件为系统禁止的类型!', '-1');
exit;
}
if ($exname == '') {
$filename = $cfg_user_dir . "/{$userid}/" . dd2char($nowtme . '-' . mt_rand(1000, 9999)) . '.' . $sname;
} else {
$filename = $cfg_user_dir . "/{$userid}/{$exname}." . $sname;
}
move_uploaded_file($GLOBALS[$upname], $cfg_basedir . $filename) or die("上传文件到 {$filename} 失败!");
@unlink($GLOBALS[$upname]);
if (@filesize($cfg_basedir . $filename) > $GLOBALS['cfg_mb_upload_size'] * 1024) {
@unlink($cfg_basedir . $filename);
ShowMsg('你上传的文件超出系统大小限制!', '-1');
exit;
}
//加水印或缩小图片
if ($utype == 'image') {
include_once DEDEINC . '/image.func.php';
if ($maxwidth > 0 || $maxheight > 0) {
ImageResize($cfg_basedir . $filename, $maxwidth, $maxheight);
} else {
if ($water) {
WaterImg($cfg_basedir . $filename);
}
}
}
return $filename;
} else {
//强制禁止的文件类型
if ($handname == '') {
return $handname;
} else {
if (eregi("\\.(asp|php|pl|cgi|shtm|js)", $handname)) {
exit('Not allow filename for not safe!');
} else {
if (!eregi("\\.(" . $allAllowType . ")\$", $handname)) {
exit('Not allow filename for filetype!');
} else {
if (!eregi('^http:', $handname) && !eregi('^' . $cfg_user_dir . '/' . $userid, $handname) && !$isadmin) {
exit('Not allow filename for not userdir!');
}
}
}
}
return $handname;
}
//.........这里部分代码省略.........
示例8: GetCurContent
/**
* 获得文章body里的外部资源
*
* @access public
* @param string $body 文档内容
* @return string
*/
function GetCurContent($body)
{
global $cfg_multi_site, $cfg_basehost, $cfg_basedir, $cfg_image_dir, $arcID, $cuserLogin, $dsql;
$cfg_uploaddir = $cfg_image_dir;
$htd = new DedeHttpDown();
$basehost = "http://" . $_SERVER["HTTP_HOST"];
$img_array = array();
preg_match_all("/src=[\"|'|\\s]{0,}(http:\\/\\/([^>]*)\\.(gif|jpg|png))/isU", $body, $img_array);
$img_array = array_unique($img_array[1]);
//修改DEDECMS默认的远程图片的下载保存路径
//$imgUrl = $cfg_uploaddir.'/'.MyDate("ymd", time());
$imgUrl = '/image';
$imgPath = $cfg_basedir . $imgUrl;
if (!is_dir($imgPath . '/')) {
MkdirAll($imgPath, $GLOBALS['cfg_dir_purview']);
CloseFtp();
}
$milliSecond = MyDate('His', time());
foreach ($img_array as $key => $value) {
if (preg_match("#" . $basehost . "#i", $value)) {
continue;
}
if ($cfg_basehost != $basehost && preg_match("#" . $cfg_basehost . "#i", $value)) {
continue;
}
if (!preg_match("#^http:\\/\\/#i", $value)) {
continue;
}
$htd->OpenUrl($value);
$itype = $htd->GetHead("content-type");
$itype = substr($value, -4, 4);
if (!preg_match("#\\.(jpg|gif|png)#i", $itype)) {
if ($itype == 'image/gif') {
$itype = ".gif";
} else {
if ($itype == 'image/png') {
$itype = ".png";
} else {
$itype = '.jpg';
}
}
}
$milliSecondN = dd2char($milliSecond . mt_rand(1000, 8000));
$value = trim($value);
$rndFileName = $imgPath . '/' . $milliSecondN . '-' . $key . $itype;
$fileurl = $imgUrl . '/' . $milliSecondN . '-' . $key . $itype;
$rs = $htd->SaveToBin($rndFileName);
if ($rs) {
$info = '';
$imginfos = GetImageSize($rndFileName, $info);
$fsize = filesize($rndFileName);
//保存图片附件信息
$inquery = "INSERT INTO `#@__uploads`(arcid,title,url,mediatype,width,height,playtime,filesize,uptime,mid)\n\t\t\tVALUES ('{$arcID}','{$rndFileName}','{$fileurl}','1','{$imginfos[0]}','{$imginfos['1']}','0','{$fsize}','" . time() . "','" . $cuserLogin->getUserID() . "'); ";
$dsql->ExecuteNoneQuery($inquery);
$fid = $dsql->GetLastID();
AddMyAddon($fid, $fileurl);
if ($cfg_multi_site == 'Y') {
$fileurl = $cfg_basehost . $fileurl;
}
$body = str_replace($value, $fileurl, $body);
@WaterImg($rndFileName, 'down');
}
}
$htd->Close();
return $body;
}
示例9: GetFieldValue
/**
* 处理不同类型的数据
*
* @access public
* @param string $dvalue 默认值
* @param string $dtype 默认类型
* @param int $aid 文档ID
* @param string $job 操作类型
* @param string $addvar 值
* @param string $admintype 管理类型
* @param string $fieldname 变量类型
* @return string
*/
function GetFieldValue($dvalue, $dtype, $aid = 0, $job = 'add', $addvar = '', $admintype = 'admin', $fieldname = '')
{
global $cfg_basedir, $cfg_cmspath, $adminid, $cfg_ml, $cfg_cookie_encode;
if (!empty($adminid)) {
$adminid = $adminid;
} else {
$adminid = isset($cfg_ml) ? $cfg_ml->M_ID : 1;
}
if ($dtype == 'int') {
if ($dvalue == '') {
return 0;
}
return GetAlabNum($dvalue);
} else {
if ($dtype == 'stepselect') {
$dvalue = trim(preg_replace("#[^0-9\\.]#", "", $dvalue));
return $dvalue;
} else {
if ($dtype == 'float') {
if ($dvalue == '') {
return 0;
}
return GetAlabNum($dvalue);
} else {
if ($dtype == 'datetime') {
if ($dvalue == '') {
return 0;
}
return GetMkTime($dvalue);
} else {
if ($dtype == 'checkbox') {
$okvalue = '';
if (is_array($dvalue)) {
$okvalue = join(',', $dvalue);
}
return $okvalue;
} else {
if ($dtype == "htmltext") {
if ($admintype == 'member' || $admintype == 'diy') {
$dvalue = HtmlReplace($dvalue, -1);
}
return $dvalue;
} else {
if ($dtype == "multitext") {
if ($admintype == 'member' || $admintype == 'diy') {
$dvalue = HtmlReplace($dvalue, 0);
}
return $dvalue;
} else {
if ($dtype == "textdata") {
$ipath = $cfg_cmspath . "/data/textdata";
$tpath = ceil($aid / 5000);
if (!is_dir($cfg_basedir . $ipath)) {
MkdirAll($cfg_basedir . $ipath, $GLOBALS['cfg_dir_purview']);
}
if (!is_dir($cfg_basedir . $ipath . '/' . $tpath)) {
MkdirAll($cfg_basedir . $ipath . '/' . $tpath, $GLOBALS['cfg_dir_purview']);
}
$ipath = $ipath . '/' . $tpath;
$filename = "{$ipath}/{$aid}-" . cn_substr(md5($cfg_cookie_encode), 0, 16) . ".txt";
//会员投稿内容安全处理
if ($admintype == 'member' || $admintype == 'diy') {
$dvalue = HtmlReplace($dvalue, -1);
}
$fp = fopen($cfg_basedir . $filename, "w");
fwrite($fp, stripslashes($dvalue));
fclose($fp);
CloseFtp();
return $filename;
} else {
if ($dtype == 'img' || $dtype == 'imgfile') {
if (preg_match("#[\\|/]uploads[\\|/]userup#", $dvalue)) {
return $dvalue;
}
if ($admintype == 'diy') {
$iurl = MemberUploads($fieldname, '', 0, 'image', '', -1, -1, false);
return $iurl;
}
$iurl = stripslashes($dvalue);
if (trim($iurl) == '') {
return '';
}
$iurl = trim(str_replace($GLOBALS['cfg_basehost'], "", $iurl));
$imgurl = "{dede:img text='' width='' height=''} " . $iurl . " {/dede:img}";
if (preg_match("/^http:\\/\\//i", $iurl) && $GLOBALS['cfg_isUrlOpen']) {
//远程图片
$reimgs = '';
//.........这里部分代码省略.........
示例10: GetCurContent
function GetCurContent($body)
{
global $cfg_multi_site,$cfg_basehost;
$cfg_uploaddir = $GLOBALS['cfg_image_dir'];
$cfg_basedir = $GLOBALS['cfg_basedir'];
$htd = new DedeHttpDown();
$basehost = "http://".$_SERVER["HTTP_HOST"];
/*
//避免删除本地链接
if($cfg_multi_site == 'N'){
$body = str_replace(strtolower($basehost),"",$body);
$body = str_replace(strtoupper($basehost),"",$body);
}else{
if($cfg_basehost!=$basehost){
$body = str_replace(strtolower($basehost),$cfg_basehost,$body);
$body = str_replace(strtoupper($basehost),$cfg_basehost,$body);
}
}
*/
$img_array = array();
preg_match_all("/(src|SRC)=[\"|'| ]{0,}(http:\/\/(.*)\.(gif|jpg|jpeg|bmp|png))/isU",$body,$img_array);
$img_array = array_unique($img_array[2]);
$imgUrl = $cfg_uploaddir."/".strftime("%y%m%d",time());
$imgPath = $cfg_basedir.$imgUrl;
if(!is_dir($imgPath."/")){
MkdirAll($imgPath,$GLOBALS['cfg_dir_purview']);
CloseFtp();
}
$milliSecond = strftime("%H%M%S",time());
foreach($img_array as $key=>$value)
{
if(eregi($basehost,$value)) continue;
if($cfg_basehost!=$basehost && eregi($cfg_basehost,$value)) continue;
if(!eregi("^http://",$value)) continue;
//随机命名文件
$htd->OpenUrl($value);
$itype = $htd->GetHead("content-type");
if($itype=="image/gif") $itype = ".gif";
else if($itype=="image/png") $itype = ".png";
else $itype = ".jpg";
$value = trim($value);
$rndFileName = $imgPath."/".$milliSecond.$key.$itype;
$fileurl = $imgUrl."/".$milliSecond.$key.$itype;
//下载并保存文件
$rs = $htd->SaveToBin($rndFileName);
if($rs){
$body = str_replace($value,$fileurl,$body);
@WaterImg($rndFileName,'down');
}
}
$htd->Close();
return $body;
}
示例11: GetCurContent
/**
* 获得文章body里的外部资源
*
* @access public
* @param string $body 内容
* @return string
*/
function GetCurContent(&$body)
{
global $cfg_multi_site, $cfg_basehost, $cfg_basedir, $cfg_user_dir, $title, $cfg_ml;
include_once DEDEINC . "/dedecollection.func.php";
$htd = new DedeHttpDown();
$basehost = "http://" . $_SERVER["HTTP_HOST"];
$img_array = array();
preg_match_all("/(src|SRC)=[\"|'| ]{0,}(http:\\/\\/([^>]*)\\.(gif|jpg|png))/isU", $body, $img_array);
$img_array = array_unique($img_array[2]);
$imgUrl = $cfg_user_dir . "/" . $cfg_ml->M_ID;
$imgPath = $cfg_basedir . $imgUrl;
if (!is_dir($imgPath . "/")) {
MkdirAll($imgPath, $GLOBALS['cfg_dir_purview']);
CloseFtp();
}
$milliSecond = MyDate("ymdHis", time());
foreach ($img_array as $key => $value) {
if (preg_match("#" . $basehost . "#i", $value)) {
continue;
}
if ($cfg_basehost != $basehost && preg_match("#" . $cfg_basehost . "#i", $value)) {
continue;
}
if (!preg_match("#^http:\\/\\/#i", $value)) {
continue;
}
$htd->OpenUrl($value);
$itype = $htd->GetHead("content-type");
$itype = substr($value, -4, 4);
if (!preg_match("#\\.(jpg|gif|png)#i", $itype)) {
if ($itype == 'image/gif') {
$itype = ".gif";
} else {
if ($itype == 'image/png') {
$itype = ".png";
} else {
$itype = '.jpg';
}
}
}
$milliSecondN = dd2char($milliSecond . '-' . mt_rand(1000, 8000));
$value = trim($value);
$rndFileName = $imgPath . "/" . $milliSecondN . '-' . $key . $itype;
$fileurl = $imgUrl . "/" . $milliSecondN . '-' . $key . $itype;
$rs = $htd->SaveToBin($rndFileName);
if ($rs) {
$body = str_replace($value, $fileurl, $body);
@WaterImg($rndFileName, 'down');
}
$info = '';
$imginfos = GetImageSize($rndFileName, $info);
SaveUploadInfo($title, $fileurl, 1, $imginfos);
}
$htd->Close();
return $body;
}
示例12: GetFieldValue
function GetFieldValue($dvalue,$dtype,$aid=0,$job='add',$addvar='',$admintype='admin')
{
global $cfg_basedir,$cfg_cmspath,$adminID,$cfg_ml;
if(!empty($adminID)) $adminid = $adminID;
else $adminid = $cfg_ml->M_ID;
if($dtype=="int"){
return GetAlabNum($dvalue);
}
else if($dtype=="float"){
return GetAlabNum($dvalue);
}
else if($dtype=="datetime"){
return GetMkTime($dvalue);
}
else if($dtype=="checkbox"){
$okvalue = '';
if(is_array($dvalue)){
foreach($dvalue as $v){ $okvalue .= ($okvalue=='' ? $v : ",{$v}"); }
}
return $okvalue;
}
else if($dtype=="textdata")
{
if($job=='edit')
{
$addvarDirs = explode('/',$addvar);
$addvarDir = ereg_replace("/".$addvarDirs[count($addvarDirs)-1]."$","",$addvar);
$mdir = $cfg_basedir.$addvarDir;
if(!is_dir($mdir)){ MkdirAll($mdir); }
$fp = fopen($cfg_basedir.$addvar,"w");
fwrite($fp,stripslashes($dvalue));
fclose($fp);
CloseFtp();
return $addvar;
}else{
$ipath = $cfg_cmspath."/data/textdata";
$tpath = ceil($aid/5000);
if(!is_dir($cfg_basedir.$ipath)) MkdirAll($cfg_basedir.$ipath,$GLOBALS['cfg_dir_purview']);
if(!is_dir($cfg_basedir.$ipath.'/'.$tpath)) MkdirAll($cfg_basedir.$ipath.'/'.$tpath,$GLOBALS['cfg_dir_purview']);
$ipath = $ipath.'/'.$tpath;
$filename = "{$ipath}/{$aid}.txt";
$fp = fopen($cfg_basedir.$filename,"w");
fwrite($fp,stripslashes($dvalue));
fclose($fp);
CloseFtp();
return $filename;
}
}
else if($dtype=="img"||$dtype=="imgfile")
{
$iurl = stripslashes($dvalue);
if(trim($iurl)=="") return "";
$iurl = trim(str_replace($GLOBALS['cfg_basehost'],"",$iurl));
$imgurl = "{dede:img text='' width='' height=''} ".$iurl." {/dede:img}";
if(eregi("^http://",$iurl) && $GLOBALS['cfg_isUrlOpen']) //远程图片
{
$reimgs = "";
if($GLOBALS['cfg_isUrlOpen']){
$reimgs = GetRemoteImage($iurl,$adminid);
if(is_array($reimgs)){
if($dtype=="imgfile") $imgurl = $reimgs[1];
else $imgurl = "{dede:img text='' width='".$reimgs[1]."' height='".$reimgs[2]."'} ".$reimgs[0]." {/dede:img}";
}
}else{
if($dtype=="imgfile") $imgurl = $iurl;
else $imgurl = "{dede:img text='' width='' height=''} ".$iurl." {/dede:img}";
}
}
else if($iurl!=""){ //站内图片
$imgfile = $cfg_basedir.$iurl;
if(is_file($imgfile)){
$info = '';
$imginfos = GetImageSize($imgfile,$info);
if($dtype=="imgfile") $imgurl = $iurl;
else $imgurl = "{dede:img text='' width='".$imginfos[0]."' height='".$imginfos[1]."'} $iurl {/dede:img}";
}
}
return addslashes($imgurl);
}else{
return $dvalue;
}
}
示例13: GetCurContent
function GetCurContent($body)
{
global $cfg_multi_site, $cfg_basehost, $cfg_basedir, $cfg_image_dir;
$cfg_uploaddir = $cfg_image_dir;
$htd = new DedeHttpDown();
$basehost = "http://" . $_SERVER["HTTP_HOST"];
$img_array = array();
preg_match_all("/src=[\"|'|\\s]{0,}(http:\\/\\/([^>]*)\\.(gif|jpg|png))/isU", $body, $img_array);
$img_array = array_unique($img_array[1]);
$imgUrl = $cfg_uploaddir . '/' . MyDate("ymd", time());
$imgPath = $cfg_basedir . $imgUrl;
if (!is_dir($imgPath . '/')) {
MkdirAll($imgPath, $GLOBALS['cfg_dir_purview']);
CloseFtp();
}
$milliSecond = MyDate('His', time());
foreach ($img_array as $key => $value) {
if (eregi($basehost, $value)) {
continue;
}
if ($cfg_basehost != $basehost && eregi($cfg_basehost, $value)) {
continue;
}
if (!eregi("^http://", $value)) {
continue;
}
$htd->OpenUrl($value);
$itype = $htd->GetHead("content-type");
$itype = substr($value, -4, 4);
if (!eregi("\\.(jpg|gif|png)", $itype)) {
if ($itype == 'image/gif') {
$itype = ".gif";
} else {
if ($itype == 'image/png') {
$itype = ".png";
} else {
$itype = '.jpg';
}
}
}
$milliSecondN = dd2char($milliSecond . mt_rand(1000, 8000));
$value = trim($value);
$rndFileName = $imgPath . '/' . $milliSecondN . '-' . $key . $itype;
$fileurl = $imgUrl . '/' . $milliSecondN . '-' . $key . $itype;
$rs = $htd->SaveToBin($rndFileName);
if ($rs) {
if ($cfg_multi_site == 'Y') {
$fileurl = $cfg_basehost . $fileurl;
}
$body = str_replace($value, $fileurl, $body);
@WaterImg($rndFileName, 'down');
}
}
$htd->Close();
return $body;
}