CMS插件分享网

影子是一个会撒谎的精灵,它在虚空中流浪和等待被发现之间;在存在与不存在之间....

位置:主页 > 织梦二次开发 >

【织梦文章模型】缩略图和文章内容图片发布到远程服务器

发布时间:2019-11-25 09:36作者:√無∑情—浏览(169)

    1、打开 /dede/article_add.php 找到

    //生成HTML
    在它上面加入
    $row1 = $dsql->GetOne("SELECT * FROM `#@_multiserv_config`");
    $isftp = $row1['remoteuploads'];
    $ftpurl = $row1['remoteupUrl'];
    $ftpconfig = $row1['servinfo'];
    $ftpconfig_arr = array();
    $ftpconfig_txt = explode('|', $ftpconfig);
    foreach($ftpconfig_txt as $str){
    	$ftpconfig_arr[] = trim($str);
    }
     
    if($isftp == 1){		
    	$config = array(
    	  'hostname' => $ftpconfig_arr[1],
    	  'username' => $ftpconfig_arr[3],
    	  'password' => $ftpconfig_arr[4],
    	  'port' => $ftpconfig_arr[2],
    	  'debug' => 'TRUE'
    	);
    	$ftps = new FTP(); 
    	$ftps->connect($config);
    	$row2 = $dsql->GetOne("SELECT litpic FROM `#@_archives` WHERE id=$arcID");
    	$imglist = $row2['litpic'];
    	$row3 = $dsql->GetOne("SELECT body FROM `$addtable` WHERE aid=$arcID");
    	preg_match_all("/<img([^>]*)\s*src=('|\")([^'\"]+)('|\")/", $row3['body'], $matches);
    	$arr=array_unique($matches[3]);
    	foreach($arr as $key){ 
    		$imglist .= ','.$key; 
    	}
    	$imglistarr = array();
    	$imglist_txt = explode(',', $imglist);
    	foreach($imglist_txt as $str){
    		$remotefile = str_replace(DEDEROOT, '', $str);
    		$localfile = '..'.$remotefile;
    		$remotefile2 = str_replace('uploads/', 'uploadfile/', $remotefile);
    		$remotedir = preg_replace('/[^\/]*\.(jpg|gif|bmp|png)/', '', $remotefile2);
    		$ftps->rmkdir($remotedir);
    		$ftps->upload($localfile, $remotefile2);
    	}
    	$dsql->ExecuteNoneQuery("UPDATE `#@_archives` SET `litpic`=REPLACE(`litpic`,'/uploads','$ftpurl/uploadfile') WHERE `litpic` LIKE '%/uploads%' AND `id` = $arcID");
    	$dsql->ExecuteNoneQuery("UPDATE `$addtable` SET `body`=REPLACE(`body`,'/uploads','$ftpurl/uploadfile') WHERE `body` LIKE '%/uploads%' AND `aid` = $arcID");
    	$ftps->close();
    }

    2、打开 /dede/article_edit.php 找到

    //生成HTML

    在它上面加入
     

    $row1 = $dsql->GetOne("SELECT * FROM `#@_multiserv_config`");
    $isftp = $row1['remoteuploads'];
    $ftpurl = $row1['remoteupUrl'];
    $ftpconfig = $row1['servinfo'];
    $ftpconfig_arr = array();
    $ftpconfig_txt = explode('|', $ftpconfig);
    foreach($ftpconfig_txt as $str){
    	$ftpconfig_arr[] = trim($str);
    }
     
    if($isftp == 1){
    	$config = array(
    	  'hostname' => $ftpconfig_arr[1],
    	  'username' => $ftpconfig_arr[3],
    	  'password' => $ftpconfig_arr[4],
    	  'port' => $ftpconfig_arr[2],
    	  'debug' => 'TRUE'
    	);
    	$ftps = new FTP(); 
    	$ftps->connect($config);
    	
    	$row2 = $dsql->GetOne("SELECT litpic FROM `#@_archives` WHERE id=$id");
    	$imglist = $row2['litpic'];
    	$row3 = $dsql->GetOne("SELECT body FROM `$addtable` WHERE aid=$id");
    	preg_match_all("/<img([^>]*)\s*src=('|\")([^'\"]+)('|\")/", $row3['body'], $matches);
    	$arr=array_unique($matches[3]);
    	foreach($arr as $key){ 
    		$imglist .= ','.$key; 
    	}
    	$imglistarr = array();
    	$imglist_txt = explode(',', $imglist);
    	foreach($imglist_txt as $str){
    		if(preg_match('https://www.dedehtml.com/uploads/', $str)){
    			$remotefile = str_replace(DEDEROOT, '', $str);
    			$localfile = '..'.$remotefile;
    			$remotefile2 = str_replace('uploads/', 'uploadfile/', $remotefile);
    			$remotedir = preg_replace('/[^\/]*\.(jpg|gif|bmp|png)/', '', $remotefile2);
    			$ftps->rmkdir($remotedir);
    			$ftps->upload($localfile, $remotefile2);
    		}
    	}
    	$dsql->ExecuteNoneQuery("UPDATE `#@_archives` SET `litpic`=REPLACE(`litpic`,'/uploads','$ftpurl/uploadfile') WHERE `litpic` LIKE '%/uploads%' AND `id` = $id");
    	$dsql->ExecuteNoneQuery("UPDATE `$addtable` SET `body`=REPLACE(`body`,'/uploads','$ftpurl/uploadfile') WHERE `body` LIKE '%/uploads%' AND `aid` = $id");
    	$ftps->close();
    }

    相关推荐

    织梦实现远程附件的方法(图片第三方储存)

    【织梦图集模型】缩略图和文章内容图片发布到远程服务器