kartik-v / yii2-mpdf

A Yii2 wrapper component for the mPDF library which generates PDF files from UTF-8 encoded HTML.
http://demos.krajee.com/mpdf
Other
161 stars 150 forks source link

Temp file cleanup error due to wrong paths #57

Closed gerysk closed 7 years ago

gerysk commented 7 years ago

In the Pdf.php file:

public function initTempPaths()
    {
        if (empty($this->tempPath)) {
            $this->tempPath = Yii::getAlias('@runtime/mpdf');
        }
        $prefix = $this->tempPath . DIRECTORY_SEPARATOR;
        static::definePath('_MPDF_TEMP_PATH', "{$prefix}tmp");
        static::definePath('_MPDF_TTFONTDATAPATH', "{$prefix}ttfontdata");
    }

Right now this creates the fontdata and tmp files in the runtime/mpdf folder and not in runtime/mpdf/tmp or ttfontdata folders. This prevents the cleanup for temp files 1hour old or more and can cause memory problems. It should be:

public function initTempPaths()
    {
        if (empty($this->tempPath)) {
            $this->tempPath = Yii::getAlias('@runtime/mpdf');
        }
        $prefix = $this->tempPath . DIRECTORY_SEPARATOR;
        static::definePath('_MPDF_TEMP_PATH', "{$prefix}tmp".DIRECTORY_SEPARATOR);
        static::definePath('_MPDF_TTFONTDATAPATH', "{$prefix}ttfontdata".DIRECTORY_SEPARATOR);
    }

Edit: Changed '/' to DIRECTORY_SEPARATOR

kartik-v commented 7 years ago

Check with the updated code from dev-master.

gerysk commented 7 years ago

There doesn't seem to be any changes in the function initTempPaths() in v1.0.2. I suppose the mpdf v7 update solves it. I will give it a try after it becomes a stable release. For the time being I have patched it as above for the v1.0.1

kartik-v commented 7 years ago

You are right... reopened isse for enhancement.