Skip to content

Commit

Permalink
Fixed aboslute paths not working for file uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
Toflar committed Dec 1, 2021
1 parent df188ab commit d2070fc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 2 additions & 6 deletions library/NotificationCenter/Util/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@ public static function getFileUploadPathForToken(array $file)
{
// Check if it has been saved by Contao and thus moved to it's final destination already
if (isset($file['uploaded']) && $file['uploaded'] === true) {
$basePath = TL_ROOT . '/';
if (preg_match('/^' . preg_quote($basePath, '/') . '/', $file['tmp_name'])
&& file_exists($file['tmp_name'])
) {

return str_replace($basePath, '', $file['tmp_name']);
if (file_exists($file['tmp_name'])) {
return $file['tmp_name'];
}

return null;
Expand Down
5 changes: 5 additions & 0 deletions library/NotificationCenter/Util/StringUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public static function getTokenAttachments($strAttachmentTokens, array $arrToken
$strParsedToken = \Haste\Util\StringUtil::recursiveReplaceTokensAndTags($strToken, $arrTokens, static::NO_TAGS | static::NO_BREAKS);

foreach (trimsplit(',', $strParsedToken) as $strFile) {
if (is_file($strFile)) {
$arrAttachments[$strFile] = $strFile;
continue;
}

$strFileFull = TL_ROOT . '/' . $strFile;

if (is_file($strFileFull)) {
Expand Down

4 comments on commit d2070fc

@Acta2000
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this change is the Reason for the Bug #254 ?

@cliffparnitzky
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Acta2000 When you replace the code in your environment (remove the green parts and add the red ones), you are able to check. If it works, we will know more.

@Acta2000
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked it... in Version 1.6.3 all works fine... with update to 1.6.4 the Path in ##form_file## is changed from files/folder/data.pdf to D://htdocs/contaomainfolder/files/folder/data.pd

@floespen
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change. If you want to download that file from your Server via Browser you'll get an absolute path after your URL instead of the needed relative path :/

Please sign in to comment.