douzhangjian1505 2013-04-09 23:33
浏览 51
已采纳

试图让php输出xml,而不是相对路径

I have this working fine in browser but air for ios need the full address.

<?php $path_to_image_dir = 'Games/game_images/'.$username; 

    $xml_string = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?><data> <LoaderMax name=\"gallery\">";

    if ( $handle = opendir( $path_to_image_dir ) ) {
        $i = 1;
        while (false !== ($file = readdir($handle))) {
            if ( is_file($path_to_image_dir.'/'.$file) ) {
                $xml_string .= "<ImageLoader url=\"" . $path_to_image_dir."/".$file . "\"  />";
            }
        }
        closedir($handle);
    }


$xml_string .= "</LoaderMax></data>";
$ignore = array('.','..','cgi-bin','.DS_Store');
$file = fopen($username.'_imagesfile.xml','w');
fwrite($file, $xml_string);
fclose($file);
?>

this is the xml result:

<?xml version="1.0" encoding="iso-8859-1"?><data> <LoaderMax name="gallery"><ImageLoader url="Games/game_images/mrpeepers/1365535674.jpg"  /><ImageLoader url="Games/game_images/mrpeepers/1365535527.jpg"  /></LoaderMax></data>

works on ios if address is added by hand http://wwww.mysite.ccom/Games/game_images/mrpeeper/1365535674.jpg

  • 写回答

1条回答 默认 最新

  • drblhw5731 2013-04-09 23:42
    关注

    Add $_SERVER['SERVER_NAME'] to your directory name like so:

    $xml_string .= "<ImageLoader url=\"" . $_SERVER['SERVER_NAME'] . "/" . $path_to_image_dir."/".$file . "\"  />";
    

    http://php.net/manual/en/reserved.variables.server.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波