Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php将远程动态文件下载到本地服务器_Php_File - Fatal编程技术网

php将远程动态文件下载到本地服务器

php将远程动态文件下载到本地服务器,php,file,Php,File,当我对远程服务器进行服务器端调用时 它应该实时下载feed_randomnumber.csv(随机文件名),并以相同的名称保存到本地服务器中 但它不起作用 怎么了 getfeed.php getremotetofile("http://aa.com/generatefeed.php"); public static function getremotetofile($fileurl) { $newfilename= basename($fileurl); $destinat

当我对远程服务器进行服务器端调用时

它应该实时下载feed_randomnumber.csv(随机文件名),并以相同的名称保存到本地服务器中

但它不起作用

怎么了

getfeed.php

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'));