curl - Download large file to server using php with any method -


first try:

i have used code: (thanks user580950 this answer)

// define variables $local_file = 'archive.tar'; $server_file = '/path/to/archive.tar'; $ftp_server = "1.2.3.4"; $ftp_user_name = "username"; $ftp_user_pass = "password"; $port_number = 123  $conn_id = ftp_connect($ftp_server, $port_number);  // login username , password $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);  // try download $server_file , save $local_file if (ftp_get($conn_id, $local_file, $server_file, ftp_binary)) {     echo "successfully written $local_file\n"; } else {     echo "there problem\n"; } // close connection ftp_close($conn_id); 

the archive big file less 2gb.

but after seconds see there problem.


second try:

$url = 'http://site.com/archive.tar';  file_put_contents("archive.tar", fopen($url, 'r')); 

third try:

$fh = fopen(basename($url), "wb"); $ch = curl_init($url); curl_setopt($ch, curlopt_file, $fh); curl_exec($ch); curl_close($ch); 

fourth try:

$fp = fopen (dirname(__file__) . '/archive.tar', 'w+');//this file save    information $ch = curl_init($url);//here file downloading, replace spaces %20 curl_setopt($ch, curlopt_timeout, 50); curl_setopt($ch, curlopt_file, $fp); // write curl response file curl_setopt($ch, curlopt_followlocation, true); curl_exec($ch); // curl response curl_close($ch); fclose($fp); 

fifth one:

function download($file_source, $file_target) {     $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;         }         echo ' ';         flush();     }      fclose($rh);     fclose($wh);      return true; }   set_time_limit(0);  var_dump(download($url, 'archive.tar')); // returns bool(false) 

i should thank many guys in using code, still no luck.

try ftp_pasv($conn_id, true);.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -