从服务器图像 URL 转换为绝对地址


Converting from server image URL to absolute address

我想这是一个简单的问题,但我真的找不到任何可以帮助我的东西。

正在使用图像下载脚本,为此我需要一个如下所示的图像 URL:"/home/clients/websites/w_apo/public_html/apo/wp-content/uploads/2012/05/Beautiful.jpg"[类型1]

但我拥有的是:"http://www.apo.com/wp-content/uploads/2012/05/Beautiful.jpg"[类型2]

我尝试编写一个函数,将类型 1 的 URL 返回到类型 2 的 URL,但它的效果并不好。这是它的外观:

function relativeToServerAddress($relativeURL) {
    $paths = explode('wp-content/', $relativeURL);
    $thePath = getcwd()."/wp-content"."/".$paths[1];
    return $thePath;
}

有没有更好的方法可以做到这一点?我试图找到一个预定义的功能,但失败了。

谢谢

$file = basename("http://www.apo.com/wp-content/uploads/2012/05/Beautiful.jpg");
return getcwd()."/wp-content/".$file;

?您需要告知我们您希望保留/从绝对URL移动的目录;以上只是复制文件。