Symfony 不通过 touch( ) 创建文件

Symfony not create file by touch( )

我想创建此路径的文件:/var/logs/filename.文件扩展名。但是我没有创建文件我有错误->Failed to touch "/var/logs/file.txt".

我的代码:

$fs=new Filesystem();
$fs->touch('/var/logs/file.txt');

touch() sets access and modification time for a file. The current time is used by default. You can set your own with the second argument. The third argument is the access time:

所以 touch 没有根据文档创建新文件。

阅读http://symfony.com/doc/current/components/filesystem.html

如果你想创建一个文件你需要使用函数 dumpFile();

dumpFile() allows you to dump contents to a file. It does this in an atomic manner: it writes a temporary file first and then moves it to the new file location when it's finished. This means that the user will always see either the complete old file or complete new file (but never a partially-written file):

阅读http://symfony.com/doc/current/components/filesystem.html

此代码应创建一个新的空文件。

$fs=new Filesystem();
$fs->dumpFile('/var/logs/file.txt', '');