Skip to content

Instantly share code, notes, and snippets.

@Feyisayo
Created June 4, 2015 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Feyisayo/dc0e1f4690e7e0363a52 to your computer and use it in GitHub Desktop.
Save Feyisayo/dc0e1f4690e7e0363a52 to your computer and use it in GitHub Desktop.
This script is useful in downloading files unto a webserver.
<?php
// Enter URL of file to download here.
$f = 'https://wordpress.org/latest.tar.gz';
$dest_file = fopen (basename($f), "w");
if (!$dest_file) {
echo "<p>Error: Unable to open for writing.\n";
exit;
}
$src_file = fopen ($f, "r");
if (!$src_file) {
echo "<p>Error: Unable to remote open for reading.\n";
exit;
}
// Write the data here.
while (!feof ($src_file)) {
$line = fgets ($src_file, 1024);
fwrite ($dest_file, $line);
}
fclose ($dest_file);
fclose ($src_file);
echo "File succesfully downloaded<br/>";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment