Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If "Save file" is activated, the file will not be sent as an attachment. #80

Closed
wants to merge 2 commits into from

Conversation

Ainschy
Copy link

@Ainschy Ainschy commented Sep 18, 2015

By shortening the absolute file path, the file can be sent as an attachment.

By shortening the absolute file path, the file can be sent as an attachment.
@aschempp
Copy link
Member

aschempp commented Oct 5, 2015

Makes sense to me, thanks!

However:

  • Use TL_ROOT instead of \Environment::get('documentRoot')
  • Add a check if the target file actually exists in TL_ROOT

@Toflar
Copy link
Member

Toflar commented Oct 5, 2015

And why do you do this str_replace('\\', '/',$file['tmp_name'] )? Do you run it on windows?

@Ainschy
Copy link
Author

Ainschy commented Oct 5, 2015

Yes, my development System is Windows.

@Ainschy
Copy link
Author

Ainschy commented Jan 15, 2016

Die zusätzliche Abfrage habe ich nun vereinfacht.

@Toflar
Copy link
Member

Toflar commented Jan 15, 2016

Now I understand what this should be doing, however I think this should rather look like this:

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']);
        }

        return null;
    }

    if (!is_uploaded_file($file['tmp_name'])) {

        return null;
    }

    $tmpDir   = 'system/tmp';
    $filePath = $tmpDir . '/' . $file['name'];
    \Files::getInstance()->move_uploaded_file($file['tmp_name'], $filePath);
    \Files::getInstance()->chmod($filePath, $GLOBALS['TL_CONFIG']['defaultFileChmod']);

    return $filePath;
}

Can you check that?

Toflar added a commit that referenced this pull request Jan 15, 2016
@Toflar Toflar closed this Jan 15, 2016
@Toflar Toflar added this to the 1.3.3 milestone Jan 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants