TCPDF icon indicating copy to clipboard operation
TCPDF copied to clipboard

Temporary Image is not cleaned up

Open danielengels opened this issue 1 year ago • 4 comments

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 avatar Feb 25 '24 10:02 danielengels

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.

danielengels avatar Feb 25 '24 10:02 danielengels

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

williamdes avatar Feb 26 '24 13:02 williamdes

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.

danielengels avatar Feb 26 '24 14:02 danielengels