numero2 / contao-proper-filenames

Replaces special characters in filenames right after upload.
https://www.numero2.de/contao/erweiterungen/proper-filenames.html
GNU Lesser General Public License v3.0
13 stars 5 forks source link

Re-add root directory to tmp_name #12

Closed fritzmg closed 3 years ago

fritzmg commented 3 years ago

Currently the following error will occur, when the saving feature for a file upload in the front end form generator is enabled:

// edit: you also need to enable Send form data via e-mail in the settings of the form.

InvalidArgumentException:
Path "files/foobar" is not inside the Contao root dir "/var/www/contao"

  at vendor\contao\core-bundle\src\Resources\contao\library\Contao\StringUtil.php:1221
  at Contao\StringUtil::stripRootDir('files/foobar')
     (vendor\contao\core-bundle\src\Resources\contao\forms\Form.php:441)
  at Contao\Form->processFormData(array(…))
     (vendor\contao\core-bundle\src\Resources\contao\forms\Form.php:259)
  at Contao\Form->compile()
     (vendor\contao\core-bundle\src\Resources\contao\classes\Hybrid.php:232)
  at Contao\Hybrid->generate()
     (vendor\contao\core-bundle\src\Resources\contao\forms\Form.php:94)
  at Contao\Form->generate()
     (vendor\contao\core-bundle\src\Resources\contao\library\Contao\Controller.php:612)
  at Contao\Controller::getContentElement(object(ContentModel), 'main')
     (vendor\contao\core-bundle\src\Resources\contao\modules\ModuleArticle.php:218)
  at Contao\ModuleArticle->compile()
     (vendor\contao\core-bundle\src\Resources\contao\modules\Module.php:214)
  at Contao\Module->generate()
     (vendor\contao\core-bundle\src\Resources\contao\modules\ModuleArticle.php:71)
  at Contao\ModuleArticle->generate(false)
     (vendor\contao\core-bundle\src\Resources\contao\library\Contao\Controller.php:540)
  at Contao\Controller::getArticle(object(ArticleModel), false, false, 'main')
     (vendor\contao\core-bundle\src\Resources\contao\library\Contao\Controller.php:381)
  at Contao\Controller::getFrontendModule('0', 'main')
     (vendor\contao\core-bundle\src\Resources\contao\pages\PageRegular.php:168)
  at Contao\PageRegular->prepare(object(PageModel))
     (vendor\contao\core-bundle\src\Resources\contao\pages\PageRegular.php:48)
  at Contao\PageRegular->getResponse(object(PageModel), true)
     (vendor\contao\core-bundle\src\Resources\contao\controllers\FrontendIndex.php:337)
  at Contao\FrontendIndex->renderPage(object(PageModel))
     (vendor\symfony\http-kernel\HttpKernel.php:158)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor\symfony\http-kernel\HttpKernel.php:80)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor\symfony\http-kernel\Kernel.php:201)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (web\index.php:31)
  at require('web\\index.php')
     (web\app.php:4)      

This is because CheckFilenames::renameFormUploads strips the root dir here, and subsequently CheckFilenames::renameFiles will also return a relative path, which is then directly used for tmp_name here. However Contao expects tmp_name to be an absolute path.

fritzmg commented 3 years ago

Hm, I guess this won't work, if the saving feature is not enabled. I'll have to work on this further.

bennyborn commented 3 years ago

I would agree that we should add the TL_ROOT after renaming but I can't reproduce the problem itself.

The following configuration seems to work without a problem:

image

fritzmg commented 3 years ago

but I can't reproduce the problem itself.

Yeah, there is an additional precondition: you need to enable Send form data via e-mail for the form. Then the issue occurs.

fritzmg commented 3 years ago

Hm, I guess this won't work, if the saving feature is not enabled. I'll have to work on this further.

Should be fine, CheckFilenames::renameFormUploads will only apply to widgets with storeFile enabled anyway.

bennyborn commented 3 years ago

I guess with the solution in 713d3748edf1cc3df20c875073108a05e3a5e2bf we do not need to care about this anymore?

fritzmg commented 3 years ago

Indeed :)