file_put_contents

Supported Versions: PHP 5, PHP 7, PHP 8
Write data to a file
<?php file_put_contents(    string $filename,    mixed $data,    int $flags = 0,    ?resource $context = null): int|false
<?php     public function refreshDatabaseFile()

    {

        file_put_contents($this->connection->getDatabaseName(), '');

    }

}
<?php     public function put($path, $contents, $lock = false)

    {

        return file_put_contents($path, $contents, $lock ? LOCK_EX : 0);

    }
<?php             chmod($tempPath, 0777 - umask());

        }



        file_put_contents($tempPath, $content);



        rename($tempPath, $path);

    }
<?php     public function replaceInFile($search, $replace, $path)

    {

        file_put_contents($path, str_replace($search, $replace, file_get_contents($path)));

    }
<?php     public function append($path, $data, $lock = false)

    {

        return file_put_contents($path, $data, FILE_APPEND | ($lock ? LOCK_EX : 0));

    }
<?php             return $path;

        }



        file_put_contents($path, $this->formatFacadeStub(

            $alias, file_get_contents(__DIR__.'/stubs/facade.stub')

        ));



        return $path;

    }
<?php             );



            if (! str_contains($bootstrapScript, './echo')) {

                file_put_contents(

                    $bootstrapScriptPath,

                    trim($bootstrapScript.PHP_EOL.file_get_contents(__DIR__.'/stubs/echo-bootstrap-js.stub')).PHP_EOL,

                );

            }

        }
<?php             return;

        }



        file_put_contents(

            $path,

            '<div>

    <!-- '.Inspiring::quotes()->random().' -->

</div>'

        );



        if ($onSuccess) {

            $onSuccess();
<?php             $this->laravel->maintenanceMode()->activate($downFilePayload);



            file_put_contents(

                storage_path('framework/maintenance.php'),

                file_get_contents(__DIR__.'/stubs/maintenance-mode.stub')

            );



            $this->laravel->get('events')->dispatch(new MaintenanceModeEnabled());
<?php     {

        $this->callSilent('event:clear');



        file_put_contents(

            $this->laravel->getCachedEventsPath(),

            '<?php return '.var_export($this->getEvents(), true).';'

        );



        $this->components->info('Events cached successfully.');

    }
<?php             return false;

        }



        file_put_contents($this->laravel->environmentFilePath(), $replaced);



        return true;

    }
<?php             if ((! $this->option('existing') && (! file_exists($to) || $this->option('force')))

                || ($this->option('existing') && file_exists($to))) {

                file_put_contents($to, file_get_contents($from));

            }

        }
<?php             if ((! $this->option('existing') && (! file_exists($to) || $this->option('force')))

                || ($this->option('existing') && file_exists($to))) {

                file_put_contents($to, file_get_contents($from));

            }

        }
<?php     public function activate(array $payload): void

    {

        file_put_contents(

            $this->path(),

            json_encode($payload, JSON_PRETTY_PRINT)

        );

    }
<?php         $tempFile = $tempFileInfo['dirname'].'/'.$tempFileInfo['filename'].'.blade.php';



        file_put_contents($tempFile, $template);



        return new TestView(view($tempFileInfo['filename'], $data));

    }