DEV Community

Cover image for Resumable file upload in PHP: Handle large file uploads in an elegant way

Resumable file upload in PHP: Handle large file uploads in an elegant way

Konsole on December 02, 2018

Ever struggled with large file upload in PHP? Wondered if you could continue uploading where you left off without re-uploading whole data again in...
Collapse
 
ohffs profile image
ohffs

Last time I looked at Tus you couldn't control the filename on the server-side - is it still like that? I was looking to replace using Minio with it - but not being able to control the filenames/dirs was a bit of an issue :-/

Collapse
 
konsole profile image
Konsole

Hi @ohffs ,

Thank you for trying the package.

If you are using both tus-php client and server you can provide file name in client itself. For eg:

$client->setKey($uploadKey)->file('/path/to/file', 'my-awesome-file.mp4');

If you want to do it in server side you can do it using hooks which is coming soon in new version: github.com/ankitpokhrel/tus-php/pu...

$server->event()->addListener(
    'tus-server.upload.complete',
     function (\TusPhp\Events\TusEvent $event) {
        // Perform post upload operation.
        // For instance, renaming a file in your case
    });

Hope that address your issue. Feel free to open issue in case you need any help.

Collapse
 
ohffs profile image
ohffs

Oh - thanks for that! Sadly I'd be using the Golang server (embedded device so no PHP) - but I see now it has hooks too so I might be able work something out :-). Thanks for the tip! :-D