0

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?

Jon Winstanley
  • 23,010
  • 22
  • 73
  • 116

2 Answers2

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

...
Crozin
  • 43,890
  • 13
  • 88
  • 135
-1

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
Emii Khaos
  • 9,983
  • 3
  • 34
  • 57
  • I'd like to make the change inside my project ideally. Rather than relying on system config. – Jon Winstanley May 01 '14 at 11:02
  • the .htaccess should stay in your project directory. The main advantage is, this modifies the tmp directory for every library which depends on [`sys_get_temp_dir()`](http://us.php.net/sys_get_temp_dir) and not only swiftmailer. – Emii Khaos May 01 '14 at 11:22