From 84a152dc2ec2c84350a7214071422ed9b3251712 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Sat, 7 Nov 2015 15:33:48 +0100 Subject: [PATCH 1/2] FIX #3836 Unable to upload a document to an invoice under some circunstances --- htdocs/core/lib/files.lib.php | 6 +++++- htdocs/core/tpl/document_actions_post_headers.tpl.php | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index c92d5ab4f25..b30e0494b39 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -2,6 +2,7 @@ /* Copyright (C) 2008-2012 Laurent Destailleur * Copyright (C) 2012-2013 Regis Houssin * Copyright (C) 2012 Juanjo Menent + * Copyright (C) 2015 Marcos García * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -1041,10 +1042,13 @@ function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesessio // Define $destpath (path to file including filename) and $destfile (only filename) $destpath=$upload_dir . "/" . $_FILES[$varfiles]['name']; $destfile=$_FILES[$varfiles]['name']; + + $savingdocmask = dol_sanitizeFileName($savingdocmask); + if ($savingdocmask) { $destpath=$upload_dir . "/" . preg_replace('/__file__/',$_FILES[$varfiles]['name'],$savingdocmask); - $destfile=preg_replace('/__file__/',$_FILES[$varfiles]['name'],$savingdocmask); + $destfile=dol_osencode(preg_replace('/__file__/',$_FILES[$varfiles]['name'],$savingdocmask)); } $resupload = dol_move_uploaded_file($_FILES[$varfiles]['tmp_name'], $destpath, $allowoverwrite, 0, $_FILES[$varfiles]['error'], 0, $varfiles); diff --git a/htdocs/core/tpl/document_actions_post_headers.tpl.php b/htdocs/core/tpl/document_actions_post_headers.tpl.php index 75d18c2b1a5..0e91a3e182d 100644 --- a/htdocs/core/tpl/document_actions_post_headers.tpl.php +++ b/htdocs/core/tpl/document_actions_post_headers.tpl.php @@ -1,6 +1,7 @@ * Copyright (C) 2013-2014 Laurent Destailleur + * Copyright (C) 2015 Marcos García * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -48,7 +49,7 @@ if (empty($conf->global->MAIN_DISABLE_SUGGEST_REF_AS_PREFIX)) //var_dump($modulepart); if (in_array($modulepart,array('facture_fournisseur','commande_fournisseur','facture','commande','propal','ficheinter','contract','project','project_task'))) { - $savingdocmask=$object->ref.'-__file__'; + $savingdocmask=dol_sanitizeFileName($object->ref).'-__file__'; } /*if (in_array($modulepart,array('member'))) { From 4a52d3c1b1a2ca4df694e222df71b6591676e5c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Garci=CC=81a=20de=20La=20Fuente?= Date: Sat, 7 Nov 2015 15:35:00 +0100 Subject: [PATCH 2/2] Removed unwanted change --- htdocs/core/lib/files.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index b30e0494b39..7f6737afba2 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -1048,7 +1048,7 @@ function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesessio if ($savingdocmask) { $destpath=$upload_dir . "/" . preg_replace('/__file__/',$_FILES[$varfiles]['name'],$savingdocmask); - $destfile=dol_osencode(preg_replace('/__file__/',$_FILES[$varfiles]['name'],$savingdocmask)); + $destfile=preg_replace('/__file__/',$_FILES[$varfiles]['name'],$savingdocmask); } $resupload = dol_move_uploaded_file($_FILES[$varfiles]['tmp_name'], $destpath, $allowoverwrite, 0, $_FILES[$varfiles]['error'], 0, $varfiles);