php将远程动态文件下载到本地服务器
当我对远程服务器进行服务器端调用时 它应该实时下载feed_randomnumber.csv(随机文件名),并以相同的名称保存到本地服务器中 但它不起作用 怎么了 getfeed.phpphp将远程动态文件下载到本地服务器,php,file,Php,File,当我对远程服务器进行服务器端调用时 它应该实时下载feed_randomnumber.csv(随机文件名),并以相同的名称保存到本地服务器中 但它不起作用 怎么了 getfeed.php getremotetofile("http://aa.com/generatefeed.php"); public static function getremotetofile($fileurl) { $newfilename= basename($fileurl); $destinat
getremotetofile("http://aa.com/generatefeed.php");
public static function getremotetofile($fileurl)
{
$newfilename= basename($fileurl);
$destination=fopen($newfilename,"w");
$source=fopen($fileurl,"r");
$maxsize=3000;
$length=0;
while (($a=fread($source,1024))&&($length<$maxsize))
{
$length=$length+1024;
fwrite($destination,$a);
}
fclose($source);
fclose($destination);
}
尝试使用CURL而不是fopen,它可能在您的服务器上被禁用。
$file=”http://somelocation.com/somefile.php";代码>
$ch=curl\u init($file)代码>
$fp=@fopen(“temp.php”,“w”)代码>
curl\u setopt($ch,CURLOPT\u文件,$fp)代码>
curl_setopt($ch,CURLOPT_头,0)代码>
curl_exec($ch)代码>
curl\u close($ch)代码>
fclose($fp)代码>
$file=“temp.php”代码>
$fp=fopen($file,“r”)代码>
尝试使用CURL而不是fopen,它可能在您的服务器上被禁用。
$file=”http://somelocation.com/somefile.php";代码>
$ch=curl\u init($file)代码>
$fp=@fopen(“temp.php”,“w”)代码>
curl\u setopt($ch,CURLOPT\u文件,$fp)代码>
curl_setopt($ch,CURLOPT_头,0)代码>
curl_exec($ch)代码>
curl\u close($ch)代码>
fclose($fp)代码>
$file=“temp.php”代码>
$fp=fopen($file,“r”)代码>
定义与代码不兼容的内容。您是否在php配置中启用了allow_url_fopen?看一看定义哪些代码不起作用。您是否在php配置中启用了allow_url_fopen?看一看试试这个:
getremotetofile("http://aa.com/generatefeed.php");
public static function getremotetofile($fileurl)
{
$newfilename= basename($fileurl);
$content = file_get_contents($fileurl);
file_put_contents($newfilename, $content);
}
getremotetofile(“http://aa.com/generatefeed.php");
公共静态函数getremotetofile($fileurl)
{
$newfilename=basename($fileurl);
$content=file\u get\u contents($fileurl);
文件内容($newfilename,$content);
} 试试这个:
getremotetofile("http://aa.com/generatefeed.php");
public static function getremotetofile($fileurl)
{
$newfilename= basename($fileurl);
$content = file_get_contents($fileurl);
file_put_contents($newfilename, $content);
}
getremotetofile(“http://aa.com/generatefeed.php");
公共静态函数getremotetofile($fileurl)
{
$newfilename=basename($fileurl);
$content=file\u get\u contents($fileurl);
文件内容($newfilename,$content);
}
我使用它下载动态创建的远程csv,并将其保存在本地服务器上
我使用此方法下载动态创建的远程csv,并将其保存在本地服务器上。此方法可行,但复制的csv文件仅获得1个标题行,所有其他行无法捕获此方法可行,但复制的csv文件仅获得1个标题行,所有其他行无法捕获
file_put_contents('localFile.csv', file_get_contents('http://www.somewhere.com/function.php?action=createCSVfile'));