问题
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