if ( $type == "export" )
{
$str = "<?xml version='1.0' encoding='gb2312' ?>\n";
$sql = "select * from c02_chpage where focusid=".$focusid;
$qry = $q->query( $sql );
$str .= "<HTML>";
$str .= "<BL>";
$str .= "<Link>";
while ( $row = $q->fetch_array( $qry ) )
{
$str .= "<linklist cid='".$row['CID'].( "' focusid='".$focusid."' link='" ).base64_encode( $row['LINK'] )."' sid='".$row['SID']."' eid='".$row['EID']."' step='".$row['STEP']."' siteid='".$row['SITEID']."' linkname='".$row['LINKNAME']."'></linklist>";
}
$str .= "</Link>";
$str .= "</BL>";
$str .= "</HTML>";
$xmlfile_export = "link_export_".$focusid."_".date( "Ymd" ).".xml";
header( "Content-type: application/octet-stream" );
header( "Content-Disposition: attachment; filename=".$xmlfile_export );
echo $str;
}
else if ( $type == "import" )
{
if ( isset( $_REQUEST['upload_file_submit'] ) )
{
$uploaddir = $CF_ROOT_PATH."/web/output/";
if ( isset( $_FILES['userfile']['name'] ) )
{
$xmlfile = $uploaddir.$_FILES['userfile']['name'];
$tmpfile = $xmlfile.".!TEMP";
if ( move_uploaded_file( $_FILES['userfile']['tmp_name'], $tmpfile ) )
{
echo "文件下载成功!<br/>";
$str_encode = file_get_contents( $tmpfile );
$str_encode = str_replace( "gb2312", "UTF-8", $str_encode );
file_put_contents( $xmlfile, iconv( "gb2312", "UTF-8", $str_encode ) );
$xml = simplexml_load_file( $xmlfile );
$linklist_arr = $xml->BlueMonitor->Link->linklist;
$count = count( $linklist_arr );
$i = 0;
for ( ; $i < $count; ++$i)
{
$cid = $linklist_arr[$i]['cid'];
$link = base64_decode( $linklist_arr[$i]['link'] );
$sid = $linklist_arr[$i]['sid'];
$eid = $linklist_arr[$i]['eid'];
$step = $linklist_arr[$i]['step'];
$siteid = $linklist_arr[$i]['siteid'];
$linkname = $linklist_arr[$i]['linkname'];
$tmpqry = $q->query( "select * from c02_chpage where link='".$link."'" );
$num = $q->num_rows( $tmpqry );
if ( $num == 0 )
{
//进行操作的部分插入数据库什么的
}
}
@unlink( $xmlfile );
@unlink( $tmpfile );
@unlink( $xmlfile.".cache" );
echo "文件导入成功!<br/>";
}
}
{
$str = "<?xml version='1.0' encoding='gb2312' ?>\n";
$sql = "select * from c02_chpage where focusid=".$focusid;
$qry = $q->query( $sql );
$str .= "<HTML>";
$str .= "<BL>";
$str .= "<Link>";
while ( $row = $q->fetch_array( $qry ) )
{
$str .= "<linklist cid='".$row['CID'].( "' focusid='".$focusid."' link='" ).base64_encode( $row['LINK'] )."' sid='".$row['SID']."' eid='".$row['EID']."' step='".$row['STEP']."' siteid='".$row['SITEID']."' linkname='".$row['LINKNAME']."'></linklist>";
}
$str .= "</Link>";
$str .= "</BL>";
$str .= "</HTML>";
$xmlfile_export = "link_export_".$focusid."_".date( "Ymd" ).".xml";
header( "Content-type: application/octet-stream" );
header( "Content-Disposition: attachment; filename=".$xmlfile_export );
echo $str;
}
else if ( $type == "import" )
{
if ( isset( $_REQUEST['upload_file_submit'] ) )
{
$uploaddir = $CF_ROOT_PATH."/web/output/";
if ( isset( $_FILES['userfile']['name'] ) )
{
$xmlfile = $uploaddir.$_FILES['userfile']['name'];
$tmpfile = $xmlfile.".!TEMP";
if ( move_uploaded_file( $_FILES['userfile']['tmp_name'], $tmpfile ) )
{
echo "文件下载成功!<br/>";
$str_encode = file_get_contents( $tmpfile );
$str_encode = str_replace( "gb2312", "UTF-8", $str_encode );
file_put_contents( $xmlfile, iconv( "gb2312", "UTF-8", $str_encode ) );
$xml = simplexml_load_file( $xmlfile );
$linklist_arr = $xml->BlueMonitor->Link->linklist;
$count = count( $linklist_arr );
$i = 0;
for ( ; $i < $count; ++$i)
{
$cid = $linklist_arr[$i]['cid'];
$link = base64_decode( $linklist_arr[$i]['link'] );
$sid = $linklist_arr[$i]['sid'];
$eid = $linklist_arr[$i]['eid'];
$step = $linklist_arr[$i]['step'];
$siteid = $linklist_arr[$i]['siteid'];
$linkname = $linklist_arr[$i]['linkname'];
$tmpqry = $q->query( "select * from c02_chpage where link='".$link."'" );
$num = $q->num_rows( $tmpqry );
if ( $num == 0 )
{
//进行操作的部分插入数据库什么的
}
}
@unlink( $xmlfile );
@unlink( $tmpfile );
@unlink( $xmlfile.".cache" );
echo "文件导入成功!<br/>";
}
}
}
导入导出文件,如果是链接最好是加密。