在失败的file_get_contents
问题描述:
$content = file_get_contents($image_url);
这里打开流我$image_url
是dynamic.Whenever我试图运行它显示了一些成功的拼抢数据后错误的脚本。在失败的file_get_contents
file_get_contents(http://photos.harcourts.com.au/V2/000/010/936/617-886-VIC-“CloverPark”4127SunraysiaHighwayLexton.jpg): failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request.
答
您可以使用此代码
<?php
function file_url($url){
$parts = parse_url($url);
$path_parts = array_map('rawurldecode', explode('/', $parts['path']));
return
$parts['scheme'] . '://' .
$parts['host'] .
implode('/', array_map('rawurlencode', $path_parts))
;
}
$fine_url = file_url("http://photos.harcourts.com.au/V2/000/010/936/617-886-VIC-“CloverPark”4127SunraysiaHighwayLexton.jpg");
$r = file_get_contents($fine_url);
php - file_get_contents - Downloading files with spaces in the filename not working
答
- 有
“
在您的网址找到。哪个是错误的请求。 - 使用单个qoute
'
或双重qoute"
file_get_contents
函数前后的url使其成为字符串。
例
file_get_contents('http://photos.harcourts.com.au/V2/000/010/936/617-886-VIC-“CloverPark”4127SunraysiaHighwayLexton.jpg');
,即使在浏览器不开放这个网址! –