php - Symfony 不通过 touch( ) 创建文件

标签 php symfony filesystems symfony-filesystem

我想创建这个路径的文件:/var/logs/filename.fileextension。但是我没有创建文件我有错误 ->无法触摸“/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', '');

关于php - Symfony 不通过 touch( ) 创建文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43999953/

相关文章:

php - 像 Facebook 一样按用户名对所有消息进行分组

php - 如何使用php将mysql列的子字符串插入循环内的空列中?

php - 如果用户未在 Symfony 上确认,则拒绝访问

php - 如何在 Twig 中定义数组

php - Twig 中的 {{ exception.message }} 不呈现 HTML

java - 获取文件元数据的开销(上次修改日期)

php - 无法从 Laravel 中的 SQLite 表中删除

php - preg_match数字和逗号

ubuntu - minikube 上的 kubernetes 无法输出到文件

java - 更改eclipse项目目录