title: How to upload file in chunks using PHP FTP module?
body: <p>I am good at to uploading file using PHP FTP functions. It is going well, if a file is not too large. But when the file size gets large size, it is failing.</p>
  
  <p>So I need a code sample that connects to FTP and uploads file in chunks.</p>
  
  <p>My existing code.</p>
  
  <pre><code>$ftp_server = ftp_server;
  $ftp_user_name=ftp_user_name;
  $ftp_user_pass=ftp_user_pass;
  $file = $_FILES["file"]["tmp_name"];
  $remote_file = 'uploads/'.$_GET['file_name'];
  $conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
  $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
  ftp_pasv($conn_id, true);
  if ( ftp_put($conn_id, $remote_file, $file, FTP_BINARY) ) echo "Success"; else echo "Error";
  ftp_close($conn_id);
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <pre><code>var uploader = new plupload.Uploader({
      runtimes : 'html5,flash,silverlight,html4',
      browse_button : 'pickfiles', // you can pass an id...
      container: document.getElementById('container'), // ... or DOM Element itself
      url : 'upload.php',
      flash_swf_url : '../js/Moxie.swf',
      silverlight_xap_url : '../js/Moxie.xap',
  
      filters : {
          max_file_size : '1000mb',
          mime_types: [
              {title : "Image files", extensions : "jpg,gif,png"},
              {title : "Video files", extensions : "mp4,wmv"}
          ]
      },
  
      init: {
          PostInit: function() {
              document.getElementById('filelist').innerHTML = '';
  
              document.getElementById('uploadfiles').onclick = function() {
                  uploader.start();
                  return false;
              };
          },
  
          FilesAdded: function(up, files) {
              plupload.each(files, function(file) {
                  document.getElementById('filelist').innerHTML += '&lt;div id="' + file.id + '"&gt;' + file.name + ' (' + plupload.formatSize(file.size) + ') &lt;b&gt;&lt;/b&gt;&lt;/div&gt;';
              });
          },
  
          UploadProgress: function(up, file) {
              document.getElementById(file.id).getElementsByTagName('b')[0].innerHTML = '&lt;span&gt;' + file.percent + "%&lt;/span&gt;";
          },
  
          Error: function(up, err) {
              document.getElementById('console').appendChild(document.createTextNode("\nError #" + err.code + ": " + err.message));
          }
      }
  });
  
  uploader.init();
  </code></pre>
  
  <p><strong>Error</strong>
  <a href="https://i.stack.imgur.com/GSVLD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GSVLD.png" alt="Error"></a></p>