mkdir($dir); } elseif (! is_writable($dir)) { throw new IOException(sprintf('Unable to write to the "%s" directory.', $dir), 0, null, $dir); } // "tempnam" did not work with VFSStream for tests $tmpFile = dirname($filename) . '/temp_' . md5(time() . basename($filename)); if (false === @file_put_contents($tmpFile, $content)) { throw new IOException(sprintf('Failed to write file "%s".', $filename), 0, null, $filename); } try { $this->rename($tmpFile, $filename, true); } catch (IOException $e) { unlink($tmpFile); throw $e; } if (null !== $mode) { $this->chmod($filename, $mode); } } }