【发布时间】:2024-03-09 10:00:02
【问题描述】:
我遇到了 PHP 中的 copy() 函数的问题。
我需要将类似于https://example.co.uk/{8d988e90-a325-4a1c-a340-a489166286b8}/{14409287-2c29-4b51-91e4-0891b5619659}/main/imgnew-(2).jpg 的远程 URL 复制到我的本地驱动器。
这是我的代码中失败的部分,以及 $RemoteURL 变量的一些上下文:
$replace = array('%7B', '%7D','%28','%29');
$entities = array('{', '}','(',')');
$RemoteURL = str_replace($entities, $replace, "https://example.co.uk/{8d988e90-a325-4a1c-a340-a489166286b8}/{14409287-2c29-4b51-91e4-0891b5619659}/main/imgnew-(2).jpg");
$PicName = "new.jpg"
if(copy($RemoteURL,"C:\Users\Me\Downloads\Pictures\" . $PicName)){
echo "<script>console.log(\"(" . $RemoteURL . ") copied to waiting.\")</script>";
} else {
echo "<p class='float red'>READ ERROR</p>";
}
但是,这会引发错误:
Warning: copy(https://example.co.uk/%7B8d988e90-a325-4a1c-a340-a489166286b8%7B/%7B14409287-2c29-4b51-91e4-0891b5619659%7B/main/imgnew-%282%29.jpg): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
我在这里缺少什么,或者 PHP 不喜欢 URL 本身的什么?
【问题讨论】:
-
我的浏览器编码的是{和},而不是(),所以你可以尝试去掉这部分编码
-
@MaximKrizhanovsky 仅删除 () 无效,感谢您的建议
标签: php url str-replace