Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporary Image is not cleaned up #688

Open
danielengels opened this issue Feb 25, 2024 · 3 comments
Open

Temporary Image is not cleaned up #688

danielengels opened this issue Feb 25, 2024 · 3 comments

Comments

@danielengels
Copy link

Hi everyone,
I updated tcpdf com 5.9.201 to 6.6.5 recently.
Everything seems to work but then i recognize that the tmp directoy was filling up with temporary images that are not delted.
I am using the Image() method with @ before the image data - i also tried write html with base64 encoding, but the results are the same, the files never will get delted. Here is the code in the image function that writes the temporary file, but never delete it. Any solutions, how to solve the problem?
if (!empty($imgdata)) { // copy image to cache $original_file = $file; $file = TCPDF_STATIC::getObjFilename('img', $this->file_id); $fp = TCPDF_STATIC::fopenLocal($file, 'w'); if (!$fp) { $this->Error('Unable to write file: '.$file); } fwrite($fp, $imgdata); fclose($fp); unset($imgdata); $imsize = @getimagesize($file); if ($imsize === FALSE) { unlink($file); $file = $original_file; } }

@danielengels
Copy link
Author

Btw. I have a dirty hack, that i remember the file created here and safe the name in a variable:
$file = TCPDF_STATIC::getObjFilename('img', $this->file_id);
And at the end of the Image methode I unlink the file but seems not as a very smart way to do.

@williamdes
Copy link
Contributor

For me the unlink seems okay
I'd say since you seem to have created the file you are responsible for it?

@danielengels
Copy link
Author

I dont create the file - and I don't even know about the file.
That's why I pass from my code to TCPDF the imagedata (not the filename) a with the @ to the image method.
The code above then create the tempoary file and don't delete it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants