tecnickcom / TCPDF

Official clone of PHP library to generate PDF documents and barcodes
https://tcpdf.org
Other
4.22k stars 1.52k forks source link

Temporary Image is not cleaned up #688

Open danielengels opened 8 months ago

danielengels commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

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

danielengels commented 8 months ago

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.