PHP cURL, writing to file

后端 未结 6 989
隐瞒了意图╮
隐瞒了意图╮ 2020-12-29 09:12

I want to try connecting to a remote file and writing the output from there to a local file, this is my function:

function get_remote_file_to_cache()
{

$the         


        
6条回答
  •  庸人自扰
    2020-12-29 09:41

    In your question you have

        curl_setopt($curl, CURLOPT_FILE, $fp);
    
        curl_setopt($curl,  CURLOPT_RETURNTRANSFER, TRUE);
    

    but from PHP's curl_setopt documentation notes...

    It appears that setting CURLOPT_FILE before setting CURLOPT_RETURNTRANSFER doesn't work, presumably because CURLOPT_FILE depends on CURLOPT_RETURNTRANSFER being set.
    
    So do this:
    
    
    
    not this:
    
    
    

    ...stating "CURLOPT_FILE depends on CURLOPT_RETURNTRANSFER being set".

    Reference: https://www.php.net/manual/en/function.curl-setopt.php#99082

提交回复
热议问题