我想创建这个路径的文件:/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/