diff --git a/src/File.php b/src/File.php index 41fc479..4c0d89e 100644 --- a/src/File.php +++ b/src/File.php @@ -7,14 +7,13 @@ * A convenience class for temporary files. * * @author Michael Härtl - * @version 1.1.0 * @license http://www.opensource.org/licenses/MIT */ class File { /** - * @var bool whether to delete the tmp file when it's no longer referenced or when the request ends. - * Default is `true`. + * @var bool whether to delete the tmp file when it's no longer referenced + * or when the request ends. Default is `true`. */ public $delete = true; @@ -28,22 +27,24 @@ class File * * @param string $content the tmp file content * @param string|null $suffix the optional suffix for the tmp file - * @param string|null $prefix the optional prefix for the tmp file. If null 'php_tmpfile_' is used. - * @param string|null $directory directory where the file should be created. Autodetected if not provided. + * @param string|null $prefix the optional prefix for the tmp file. If null + * 'php_tmpfile_' is used. + * @param string|null $directory directory where the file should be + * created. Autodetected if not provided. */ public function __construct($content, $suffix = null, $prefix = null, $directory = null) { - if ($directory===null) { + if ($directory === null) { $directory = self::getTempDir(); } - if ($prefix===null) { + if ($prefix === null) { $prefix = 'php_tmpfile_'; } $this->_fileName = tempnam($directory,$prefix); - if ($suffix!==null) { - $newName = $this->_fileName.$suffix; + if ($suffix !== null) { + $newName = $this->_fileName . $suffix; rename($this->_fileName, $newName); $this->_fileName = $newName; } @@ -63,9 +64,11 @@ public function __destruct() /** * Send tmp file to client, either inline or as download * - * @param string|null $filename the filename to send. If empty, the file is streamed inline. + * @param string|null $filename the filename to send. If empty, the file is + * streamed inline. * @param string $contentType the Content-Type header - * @param bool $inline whether to force inline display of the file, even if filename is present. + * @param bool $inline whether to force inline display of the file, even if + * filename is present. */ public function send($filename = null, $contentType, $inline = false) { @@ -78,10 +81,10 @@ public function send($filename = null, $contentType, $inline = false) // #84: Content-Length leads to "network connection was lost" on iOS $isIOS = preg_match('/i(phone|pad|pod)/i', $_SERVER['HTTP_USER_AGENT']); if (!$isIOS) { - header('Content-Length: '.filesize($this->_fileName)); + header('Content-Length: ' . filesize($this->_fileName)); } - if ($filename!==null || $inline) { + if ($filename !== null || $inline) { $disposition = $inline ? 'inline' : 'attachment'; header( 'Content-Disposition: ' . $disposition . @@ -117,7 +120,11 @@ public static function getTempDir() { if (function_exists('sys_get_temp_dir')) { return sys_get_temp_dir(); - } elseif ( ($tmp = getenv('TMP')) || ($tmp = getenv('TEMP')) || ($tmp = getenv('TMPDIR')) ) { + } elseif ( + ($tmp = getenv('TMP')) || + ($tmp = getenv('TEMP')) || + ($tmp = getenv('TMPDIR')) + ) { return realpath($tmp); } else { return '/tmp';