src/Filesystem.php
/**
     * Download a file from the provided URL
     * This will use curl if it is available, if not it will 
     * fallback to using file_get_contents.
     * @param string $url
     * @return string - the full filepath to the downloaded file on the server.
     */
Download a file from the provided URL
This will use curl if it is available, if not it will
fallback to using file_get_contents.
@param string $url
@return string - the full filepath to the downloaded file on the server.
Download a file from the provided URL This will use curl if it is available if not it will fallback to using file_get_contents . @param string $url @return string - the full filepath to the downloaded file on the server .
public static function downloadFile(string $url) : string
    {
        $downloadedFilepath = tempnam(sys_get_temp_dir(), "");
        if (function_exists('curl_version'))
        {
            $fp = fopen($downloadedFilepath, 'w+');
            $ch = curl_init(str_replace(" ", "%20", $url));
            curl_setopt($ch, CURLOPT_TIMEOUT, 50);
            curl_setopt($ch, CURLOPT_FILE, $fp); 
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
            curl_exec($ch); 
            curl_close($ch);
            fclose($fp);
        }
        else
        {
            $content = file_get_contents($url);
            file_put_contents($downloadedFilepath, $content);
        }
        return $downloadedFilepath;
    }
public static function downloadFile ( string $ url ) : string { $ downloadedFilepath = tempnam ( sys_get_temp_dir ( ) , " " ) ; if ( function_exists ( 'curl_version' ) ) { $ fp = fopen ( $ downloadedFilepath , 'w+' ) ; $ ch = curl_init ( str_replace ( " " , " %20 " , $ url ) ) ; curl_setopt ( $ ch , CURLOPT_TIMEOUT , 50 ) ; curl_setopt ( $ ch , CURLOPT_FILE , $ fp ) ; curl_setopt ( $ ch , CURLOPT_FOLLOWLOCATION , true ) ; curl_exec ( $ ch ) ; curl_close ( $ ch ) ; fclose ( $ fp ) ; } else { $ content = file_get_contents ( $ url ) ; file_put_contents ( $ downloadedFilepath , $ content ) ; } return $ downloadedFilepath ; }
Download a file from the provided URL
 This will use curl if it is available, if not it will
 fallback to using file_get_contents.
Download a file from the provided URL This will use curl if it is available if not it will fallback to using file_get_contents .
// use curl if installed. Faster and probably more memory efficient.