Skip to content

Instantly share code, notes, and snippets.

@khanzadimahdi
Last active January 23, 2019 20:38
Show Gist options
  • Save khanzadimahdi/d1cbbc0013504b0fa349a99f4e133dad to your computer and use it in GitHub Desktop.
Save khanzadimahdi/d1cbbc0013504b0fa349a99f4e133dad to your computer and use it in GitHub Desktop.
download file in server using php
<?php
error_reporting(E_ALL);
ini_set('display_errors',1);
set_time_limit(0);
function download ($file_source, $file_target) {
echo 'starting';
$rh = fopen($file_source, 'rb');
$wh = fopen($file_target, 'w+b');
if (!$rh || !$wh) {
return false;
}
while (!feof($rh)) {
if (fwrite($wh, fread($rh, 4096)) === FALSE) {
return false;
}
}
fclose($rh);
fclose($wh);
echo '<br>end';
return true;
}
// download file and store it into current server
download('http://yoursite.com/filename.ext','filename.ext');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment