Change the location of the tmp directory for SwiftMailer in Symfony2

时光总嘲笑我的痴心妄想 提交于 2019-12-25 02:47:37

问题


My shared hosting does not allow me to use the root \tmp directory.

I know that the location of the temp directory can be updated using the Swift_Preferences class, however, how do I do that for a SwiftMailer instance autoloaded by Symfony2?

Is there a way to set it in my config.yml?

I think the code should be:

\Swift_Preferences::getInstance()->setTempDir($newTempDir);

But how/where can I set this config?


回答1:


There is more than a one way to do this. However, I think the best place for that would be inside boot method of your "main" bundle.

.../My/WebsiteBundle/MyWebsiteBundle.php:

...

public function boot() {
    $tmpDir = $this->container->getParameter('my_website.swift_tmp_dir');

    \Swift_Preferences::getInstance()->setTempDir($tmpDir);
}

...



回答2:


You can modify the whole parameter via a autoprepend.php script:

<?php
putenv('TMPDIR=/var/www/yourdir/tmp');

and set it in the .htaccess in your document root:

php_value auto_prepend_file /var/www/yourdir/htdocs/autoprepend.php


来源:https://stackoverflow.com/questions/23405414/change-the-location-of-the-tmp-directory-for-swiftmailer-in-symfony2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!