Skip to content

Instantly share code, notes, and snippets.

@hsleonis
Created October 17, 2016 12:24
Show Gist options
  • Select an option

  • Save hsleonis/279f24ce3d5076cba1b31235bb2fea66 to your computer and use it in GitHub Desktop.

Select an option

Save hsleonis/279f24ce3d5076cba1b31235bb2fea66 to your computer and use it in GitHub Desktop.
Download file to server with PHP
<?php
// file_put_contents("MoviePy.zip", fopen("https://github.com/Zulko/moviepy/archive/master.zip", 'r'));
function downloadFile($url, $path)
{
$newfname = $path;
$file = fopen ($url, 'rb');
$i = 0;
if ($file) {
$newf = fopen ($newfname, 'wb');
if ($newf) {
while(!feof($file)) {
fwrite($newf, fread($file, 1024 * 8), 1024 * 8);
$i++;
}
}
}
if (isset($file) && gettype($file)=='resource') {
fclose($file);
}
if (isset($newf) && gettype($newf)=='resource') {
fclose($newf);
}
return $i;
}
downloadFile('https://lgithub.com/Zulko/moviepy/archive/master.zip', 'MoviePy2.zip');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment