TYPO3  7.6
TemporaryFileByteStream.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4 * This file is part of SwiftMailer.
5 * (c) 2004-2009 Chris Corbyn
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10 
15 {
16  public function __construct()
17  {
18  $filePath = tempnam(sys_get_temp_dir(), 'FileByteStream');
19 
20  if ($filePath === false) {
21  throw new Swift_IoException('Failed to retrieve temporary file name.');
22  }
23 
24  parent::__construct($filePath, true);
25  }
26 
27  public function getContent()
28  {
29  if (($content = file_get_contents($this->getPath())) === false) {
30  throw new Swift_IoException('Failed to get temporary file content.');
31  }
32 
33  return $content;
34  }
35 
36  public function __destruct()
37  {
38  if (file_exists($this->getPath())) {
39  @unlink($this->getPath());
40  }
41  }
42 }