如果卷曲扩展程序不可用或已被禁用,有没有办法下载文件?
答案 0 :(得分:4)
您可以使用以下方式获取远程文件的内容:
<?php
$file_content = file_get_contents('http://www.the-site.com/file.txt');
?>
答案 1 :(得分:2)
这也有效。虽然你必须启用套接字。
function getcontent($server, $file,$port=80)
{
$cont = "";
$ip = gethostbyname($server);
$fp = fsockopen($ip, $port);
if (!$fp)
{
return "Unknown";
}
else
{
$com = "GET $file HTTP/1.1\r\nAccept: */*\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)\r\nHost: $server:$port\r\nConnection: Keep-Alive\r\n\r\n";
fputs($fp, $com);
while (!feof($fp))
{
$cont .= fread($fp, 500);
}
fclose($fp);
$cont = substr($cont, strpos($cont, "\r\n\r\n") + 4);
return $cont;
}
}
用法:
getcontent('google.com', '/intl/en_ALL/images/logo.gif');