hshn / base64-encoded-file

Provides handling for base64 encoded files, and the integration of symfony/form
MIT License
39 stars 24 forks source link

Temporary memory clogging #35

Closed daverdalas closed 10 months ago

daverdalas commented 10 months ago

At the beginning, many thanks for creating this package. I found it very useful. However, using it I noticed after a while that I ran out of memory on the server when using this package. It turned out that the files created with this package were never deleted. I dealt with this by extending the UploadedBase64EncodedFile class like this:

<?php

declare(strict_types=1);

namespace AppProject;

use Hshn\Base64EncodedFile\HttpFoundation\File as BaseUploadedBase64EncodedFile;

class UploadedBase64EncodedFile extends BaseUploadedBase64EncodedFile
{
    public function __destruct()
    {
        if (file_exists($this->getPathname())) {
            unlink($this->getPathname());
        }
    }
}

I can throw add this as a pull request or it might be worth mentioning in the readme that after using the class you should remember to remove the file from temporary memory so as not to clog up the server memory :)

hshn commented 10 months ago

Thank you for reporting and the solution! I tried bringing that into #37. I hope the PR will solve the issue. It will be released soon.