ip为全局时,file_get_contents返回false

时间:2018-11-07 02:45:48

标签: javascript php

我正在尝试通过file_get_contents生成xml文件。

此.xml按钮位于/project/siteadmin/set.php中。它有一个参数t = nav发送到ajax.php

$('.xml').click(function(e){
  e.preventDefault();
  if(confirm('confirm'+$(this).text()+'?')){

    var url = $(this).parent().attr('href'); 
    var page = url.split("/").pop().split('?')[0];
    var str=""; 
    var str_value=""; 
    var needVal=""; 
    var sqlWhere = {'page':page};

    if(url.indexOf("?")!=-1){
      var ary=url.split("?")[1].split("&");
      for(var ii in ary){

        str=ary[ii].split("=")[0];
        str_value = decodeURI(ary[ii].split("=")[1]);

        str_value = str_value.replace(/#./, "");

            if(!!str_value) {
              sqlWhere[str] = str_value;
            }

      }

      useAjax("exportXML",sqlWhere['t']);
      return false;
    }

    return false;
  } 
  return false;
});

这是/project/siteadmin/ajax.php 您可以将案例“ exportXML”简化为

  

file_get_contents('http://ServerNameAndPort/ProjectFolder/nav.php');

case "exportXML":
    set_time_limit(300);
    $getSQL = "Select next_table From `admin_menu` where `tables` = '" . ck_data('Val') . "'";
    $nextData = $sql->SelectDB($getSQL);
    $nextData = $nextData['data'][0]['next_table'];

    $theFolder = empty($subfolderName) ? '' : $subfolderName . '/'; //siteadmin level
    $http = isset($_SERVER["HTTPS"]) ? 'https://' : 'http://';

    $xmls = explode(',', $nextData);
    foreach ($xmls as $key => $value) {
      $arr[$key] = file_get_contents($http . $_SERVER['HTTP_HOST'] . '/' . $theFolder . $value);
    }

  break;

当服务器名称是localhost或192.168.11.30(来自本地)时。此功能工作正常。直接访问http://220.x.x.x:8081/project/nav.php也可以。

但是,如果ip是全局220.x.x.x:8081。当$('。xml')。click()失败时,file_get_contents将返回false并无法生成xml文件。 我该怎么解决?

/project/nav.php

include_once 'main.php';
$table = 'nav_setting';
$getSQL = "select column_comment from information_schema.columns where table_schema = '".DB_DATABASE."' and table_name = '".$table."' and column_name = 'id'";
$xmlfolder = $sql->SelectDB($getSQL);
$upload_img_path = $xmlfolder['data'][0]['column_comment'];
$xmlfolder = explode('/',$xmlfolder['data'][0]['column_comment']);

$dom = new DOMDocument('1.0', 'UTF-8');
$dom->formatOutput = true;

// create root element
$data = $dom->createElement("data");
$dom->appendChild($data);
# back time
# single
#
include 'nav_setting.php';

# About 
# 
# 
include 'nav_about.php';

#
# export xml
#

$dom->save($xmlfolder[0].'/data.xml');

echo $dom->saveXML();//export

//exec('xcopy '.(__DIR__).'.\\'.$xmlfolder[0].'\*.* "D:\Program Files (x86)\wall\data\" /D/K/E/Y/C/I/H', $output);
//$output = mb_convert_encoding($output, "UTF-8", "BIG5");
//print_r($output);

我尝试卷曲,但也不起作用。 XAMPP默认设置。

allow_url_fopen =打开

allow_url_include =关闭

0 个答案:

没有答案