October 2018

Monday 15 October 2018

Move large file server to server without downloading file in PHP that will save lot of time






Move large file server to server without downloading file in PHP that will save lot of time




<?php
function moveLargefile($url, $dest)
  {
    $options = array(
      CURLOPT_FILE => is_resource($dest) ? $dest : fopen($dest, 'w'),
      CURLOPT_FOLLOWLOCATION => true,
      CURLOPT_URL => $url,
      CURLOPT_FAILONERROR => true, // HTTP code > 400 will throw curl error
    );

    $ch = curl_init();
    curl_setopt_array($ch, $options);
    $return = curl_exec($ch);

    if ($return === false)
    {
      return curl_error($ch);
    }
    else
    {
      return true;
    }
  }
 
  echo moveLargefile("http://example.com/blog.zip", "./blog.zip");
?>