Download File to server from URL

How can I find the php.ini file used by the command line?
Print array to a file

All you have to do to download a file to your server is by following the solutions provided below.

solution 1

Since PHP 5.1.0, file_put_contents() supports writing piece-by-piece by passing a stream-handle as the $data parameter:

file_put_contents("Tmpfile.zip", fopen("http://someurl/file.zip", 'r'));

solution 2

private function downloadFile($url, $path)
{
    $newfname = $path;
    $file = fopen ($url, 'rb');
    if ($file) {
        $newf = fopen ($newfname, 'wb');
        if ($newf) {
            while(!feof($file)) {
                fwrite($newf, fread($file, 1024 * 8), 1024 * 8);
            }
        }
    }
    if ($file) {
        fclose($file);
    }
    if ($newf) {
        fclose($newf);
    }
}
How can I find the php.ini file used by the command line?
Print array to a file

Stay up-to-date about PHP!

We don’t spam!

en English
X
Scroll to Top