noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 143/151: Fix : when exporting files for creat


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 143/151: Fix : when exporting files for creating a PDF in ANC , the filename can be a problem if he contains some char.
Date: Sat, 4 Feb 2017 17:14:35 +0000 (UTC)

sparkyx pushed a commit to branch master
in repository noalyss.

commit c9bf802d8159bf273e2060d28a1b4cf73c545ca2
Author: Dany De Bontridder <address@hidden>
Date:   Sat Jan 28 09:41:13 2017 +0100

    Fix : when exporting files for creating a PDF in ANC , the filename can be 
a problem if he contains some char.
---
 include/class/class_document_export.php |   15 +++++++++------
 include/lib/user_common.php             |   16 +++++++++++++++-
 2 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/include/class/class_document_export.php 
b/include/class/class_document_export.php
index 57fbabc..05a95fa 100644
--- a/include/class/class_document_export.php
+++ b/include/class/class_document_export.php
@@ -128,18 +128,19 @@ class Document_Export
             if ($file[0]['jr_pj'] == '')
                 continue;
 
-            $cn->lo_export($file[0]['jr_pj'], $this->store_convert . '/' . 
$file[0]['jr_pj_name']);
+            $filename=clean_filename($file[0]['jr_pj_name']);
+            $cn->lo_export($file[0]['jr_pj'], $this->store_convert . '/' . 
$filename);
 
             // Convert this file into PDF 
             if ($file[0]['jr_pj_type'] != 'application/pdf')
             {
                 $status = 0;
-                $arg=" 
".escapeshellarg($this->store_convert.DIRECTORY_SEPARATOR.$file[0]['jr_pj_name']);
+                $arg=" 
".escapeshellarg($this->store_convert.DIRECTORY_SEPARATOR.$filename);
                 echo "arg = [".$arg."]";
                 passthru(OFFICE . " " . $arg , $status);
                 if ($status <> 0)
                 {
-                    $this->feedback[$cnt_feedback]['file'] = 
$file[0]['jr_pj_name'];
+                    $this->feedback[$cnt_feedback]['file'] = $filename;
                     $this->feedback[$cnt_feedback]['message'] = ' cannot 
convert to PDF';
                     $this->feedback[$cnt_feedback]['error'] = $status;
                     $cnt_feedback++;
@@ -169,8 +170,8 @@ class Document_Export
 
             // 
             // remove extension
-            $ext = strrpos($file[0]['jr_pj_name'], ".");
-            $file_pdf = substr($file[0]['jr_pj_name'], 0, $ext);
+            $ext = strrpos($filename, ".");
+            $file_pdf = substr($filename, 0, $ext);
             $file_pdf .=".pdf";
             
             //-----------------------------------
@@ -248,14 +249,16 @@ class Document_Export
             // Move the PDF into another temp directory 
             $this->move_file($output, 'stamp_' . $file_pdf);
         }
+        
+        // concatenate all pdf into one
         $this->concatenate_pdf();
+        
         ob_clean();
         $this->send_pdf();
 
         // remove files from "conversion folder"
         $this->clean_folder();
         
-        // concatenate all pdf into one
     }
    /**
     * @brief check that the files are installed
diff --git a/include/lib/user_common.php b/include/lib/user_common.php
index 7475f1a..6fc4a09 100644
--- a/include/lib/user_common.php
+++ b/include/lib/user_common.php
@@ -245,4 +245,18 @@ function check_parameter($p_array,$p_needed)
             }
         }
 }
-?>
+/**
+ * sanitize the filename remove character which could be a problem, 
+ * @param string $p_filename the filename to clean
+ * @return  string Filename without bad char.
+ */
+function clean_filename($p_filename)
+{
+    $filename=$p_filename;
+    foreach (array('/','*','<','>',';',',','\\',':','(',')',' ','[',']') as 
$i) {
+            $filename= str_replace($i, "-",$filename);
+    }
+    return $filename;
+
+}
+?>
\ No newline at end of file



reply via email to

[Prev in Thread] Current Thread [Next in Thread]