phplaravelftpuploadtus

Laravel ftp upload with tus


I need to upload large files throguh ftp with tus, so the file is uploading as little parts.

It is possible to upload tu s3 with tus through this packages, but unfortunately they didnt support ftp, and I cannot find any ftp tus package or solution on the web. Does anybody has a hint or some advice? https://github.com/rafaeltovar/php-tus-aws-s3 https://github.com/ankitpokhrel/tus-php


Solution

  • I managed to do it with php chunck upload from this article: https://artisansweb.net/how-to-implement-chunk-upload-in-php/

    the source code for chunk upload in php:

    $tmpfile = storage_path(PATH);

        $orig_file_size = filesize($tmpfile);
    
        $chunk_size = 256; // chunk in bytes
        $upload_start = 0;
    
        $handle = fopen($tmpfile, "rb");
    
        $fp = fopen('ftp://USERNAME:PASSWORD@HOST:21//TARGETDIR/FILENAME', 'w');
    
        while($upload_start < $orig_file_size) {
    
            $contents = fread($handle, $chunk_size);
            fwrite($fp, $contents);
    
            $upload_start += strlen($contents);
            fseek($handle, $upload_start);
        }
    
        fclose($handle);
        fclose($fp);