phpsymfonyfilesystemssymfony-filesystem

Symfony not create file by touch( )


I want to creat file this path : /var/logs/filename.fileextension . But ı dont create file ı have error ->Failed to touch "/var/logs/file.txt".

My Codes:

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

Solution

  • 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:

    So touch doesnt create a new file according to the docs.

    read http://symfony.com/doc/current/components/filesystem.html

    if you want to create a file you need to use the function 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):

    read http://symfony.com/doc/current/components/filesystem.html

    This code should create a new empty file.

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