Skip to content
This repository
Browse code

Create and remove temp dir. fixes #24, maybe #25

  • Loading branch information...
commit 1c9fae9eda14b27299d8f89b406a1d73eade9c42 1 parent 7a5bffa
Andreas Gohr authored May 19, 2012
24  DokuPDF.class.php
@@ -8,7 +8,7 @@
8 8
  * @author Andreas Gohr <andi@splitbrain.org>
9 9
  */
10 10
 
11  
-if(!defined('_MPDF_TEMP_PATH')) define('_MPDF_TEMP_PATH', $conf['tmpdir'].'/dwpdf/'.rand(1,1000));
  11
+if(!defined('_MPDF_TEMP_PATH')) define('_MPDF_TEMP_PATH', $conf['tmpdir'].'/dwpdf/'.rand(1,1000).'/');
12 12
 if(!defined('_MPDF_TTFONTDATAPATH')) define('_MPDF_TTFONTDATAPATH',$conf['cachedir'].'/mpdf_ttf/');
13 13
 require_once(dirname(__FILE__)."/mpdf/mpdf.php");
14 14
 
@@ -16,12 +16,34 @@ class DokuPDF extends mpdf {
16 16
 
17 17
     function __construct(){
18 18
         io_mkdir_p(_MPDF_TTFONTDATAPATH);
  19
+        io_mkdir_p(_MPDF_TEMP_PATH);
19 20
 
20 21
         // we're always UTF-8
21 22
         parent::__construct('UTF-8-s');
22 23
         $this->SetAutoFont(AUTOFONT_ALL);
23 24
         $this->ignore_invalid_utf8 = true;
  25
+    }
  26
+
  27
+    /**
  28
+     * Cleanup temp dir
  29
+     */
  30
+    function __destruct(){
  31
+        $this->deletedir(_MPDF_TEMP_PATH);
  32
+    }
24 33
 
  34
+    /**
  35
+     * Recursively delete a directory and its contents
  36
+     *
  37
+     * @link http://de3.php.net/manual/en/function.rmdir.php#108113
  38
+     */
  39
+    function deletedir($dir){
  40
+        foreach(glob($dir . '/*') as $file) {
  41
+            if(is_dir($file))
  42
+                $this->deletedir($file);
  43
+            else
  44
+                @unlink($file);
  45
+        }
  46
+        @rmdir($dir);
25 47
     }
26 48
 
27 49
     /**
2  plugin.info.txt
... ...
@@ -1,7 +1,7 @@
1 1
 base    dw2pdf
2 2
 author  Luigi Micco
3 3
 email   l.micco@tiscali.it
4  
-date    2012-05-11
  4
+date    2012-05-19
5 5
 name    Dw2Pdf plugin
6 6
 desc    DokuWiki to PDF converter
7 7
 url     http://www.dokuwiki.org/plugin:dw2pdf

0 notes on commit 1c9fae9

Please sign in to comment.
Something went wrong with that request. Please try again.