gpt4 book ai didi

php - 尝试让 php 使用完整的 url 而不是相对路径输出 xml

转载 作者:行者123 更新时间:2023-11-29 04:00:30 25 4
gpt4 key购买 nike

我在浏览器中工作正常,但 iOS 版的 Air 需要完整的地址。

<?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);
?>

这是 xml 结果:

<?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>

如果手动添加地址,则适用于 ios http://wwww.mysite.ccom/Games/game_images/mrpeeper/1365535674.jpg

最佳答案

将 $_SERVER['SERVER_NAME'] 添加到您的目录名称中,如下所示:

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

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

关于php - 尝试让 php 使用完整的 url 而不是相对路径输出 xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15914402/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com