XE(XpressEngine) 팁
xe 직접 file down & insert & replace
xemaker
2018. 7. 10. 09:18
<?php
//경로 xe/sc/insDocFile/insDocFile.php $module_srl=145;
define('__XE__',true);
require_once("../../config/config.inc.php");
include "Snoopy.class.php";
$snoopy = new Snoopy;
$domain="http://localhost";
$imgDir="../../img/";
$imgUrl="http://localhost/xe/img/";
$tempCont=' aa <img src="http://localhost/a.jpg"> bbb <img src="http://localhost/b.jpg"> cccc <img src="http://localhost/c.jpg"> dddd ';
$txt=preg_replace('/\s\s+/','',$txt);
$txt=preg_replace('/\r\r\n|\r\r\n|\n/','',$txt);
preg_match_all('/<img src="(.*)"/U',$tempCont,$match_img);
$match_img=$match_img[1];
if(!is_dir($imgDir)){
mkdir($imgDir);
}
foreach($match_img as $value){
$snoopy->fetch($value);
$fileName = basename($value);
$temp=fopen($imgDir.$fileName,'w');
fwrite($temp,$snoopy->results);
fclose($temp);
$newImgUrl=$imgUrl.$fileName;
$tempCont = str_replace($value,$newImgUrl,$tempCont);
}
$oContext=&Context::getInstance();
$oContext->init();
$document_srl=getNextSequence();
$oDocumentController=&getController('document');
$obj->module_srl=$module_srl;
$obj->document_srl=$document_srl;
$obj->nick_name='gary';
$obj->content=$tempCont;
$retObj=$oDocumentController->insertDocument($obj,true);
echo $retObj->message;
echo "<br>\n";
//경로 xe/sc/insDocFile/insDocFile.php $module_srl=145;
define('__XE__',true);
require_once("../../config/config.inc.php");
include "Snoopy.class.php";
$snoopy = new Snoopy;
$domain="http://localhost";
$imgDir="../../img/";
$imgUrl="http://localhost/xe/img/";
$tempCont=' aa <img src="http://localhost/a.jpg"> bbb <img src="http://localhost/b.jpg"> cccc <img src="http://localhost/c.jpg"> dddd ';
$txt=preg_replace('/\s\s+/','',$txt);
$txt=preg_replace('/\r\r\n|\r\r\n|\n/','',$txt);
preg_match_all('/<img src="(.*)"/U',$tempCont,$match_img);
$match_img=$match_img[1];
if(!is_dir($imgDir)){
mkdir($imgDir);
}
foreach($match_img as $value){
$snoopy->fetch($value);
$fileName = basename($value);
$temp=fopen($imgDir.$fileName,'w');
fwrite($temp,$snoopy->results);
fclose($temp);
$newImgUrl=$imgUrl.$fileName;
$tempCont = str_replace($value,$newImgUrl,$tempCont);
}
$oContext=&Context::getInstance();
$oContext->init();
$document_srl=getNextSequence();
$oDocumentController=&getController('document');
$obj->module_srl=$module_srl;
$obj->document_srl=$document_srl;
$obj->nick_name='gary';
$obj->content=$tempCont;
$retObj=$oDocumentController->insertDocument($obj,true);
echo $retObj->message;
echo "<br>\n";