From 686f8f59c5772edf1f39fbb9ed496612d7f08956 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Thu, 27 Sep 2012 12:20:04 +0200 Subject: [PATCH] Fix #910 : wrong file extension after substitution --- lib/Alchemy/Phrasea/Controller/Prod/Tools.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Tools.php b/lib/Alchemy/Phrasea/Controller/Prod/Tools.php index b381fbdb4f..66cd544cbd 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Tools.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Tools.php @@ -137,13 +137,20 @@ class Tools implements ControllerProviderInterface $fileName = $file->getClientOriginalName(); $size = $file->getClientSize(); + $tempoFile = tempnam(sys_get_temp_dir(), 'substit'); + unlink($tempoFile); + mkdir($tempoFile); + $tempoFile = $tempoFile . DIRECTORY_SEPARATOR . $fileName; + copy($file->getPathname(), $tempoFile); + + try { $record = new \record_adapter( $request->get('sbas_id') , $request->get('record_id') ); - $media = $app['Core']['mediavorus']->guess($file); + $media = $app['Core']['mediavorus']->guess(new \SplFileInfo($tempoFile)); $record->substitute_subdef('document', $media); @@ -155,6 +162,10 @@ class Tools implements ControllerProviderInterface } catch (\Exception $e) { $errorMessage = $e->getMessage(); } + + unlink($tempoFile); + rmdir(dirname($tempoFile)); + unlink($file->getPathname()); } else { $errorMessage = _('file is not valid'); }