Last active
January 23, 2019 20:38
-
-
Save khanzadimahdi/d1cbbc0013504b0fa349a99f4e133dad to your computer and use it in GitHub Desktop.
download file in server using php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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