file_put_contents

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

    {

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

    }

}
    public function put($path$contents$lock false)

    {

        return 
file_put_contents($path$contents$lock LOCK_EX 0);

    }
        chmod($tempPath0777 umask());



        
file_put_contents($tempPath$content);



        
rename($tempPath$path);

    }
    public function replaceInFile($search$replace$path)

    {

        
file_put_contents($pathstr_replace($search$replacefile_get_contents($path)));

    }
    public function append($path$data)

    {

        return 
file_put_contents($path$dataFILE_APPEND);

    }
            return $path;

        }



        
file_put_contents($path$this->formatFacadeStub(

            
$aliasfile_get_contents(__DIR__.'/stubs/facade.stub')

        ));



        return 
$path;

    }
            return;

        }



        
file_put_contents(

            
$path,

            
'<div>

    <!-- '
.Inspiring::quote().' -->

</div>'

        
);



        if (
$onSuccess) {

            
$onSuccess();
            $this->laravel->maintenanceMode()->activate($this->getDownFilePayload());



            
file_put_contents(

                
storage_path('framework/maintenance.php'),

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

            );



            
$this->laravel->get('events')->dispatch(MaintenanceModeEnabled::class);
    {

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



        
file_put_contents(

            
$this->laravel->getCachedEventsPath(),

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

        
);



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

    }
    protected function writeNewEnvironmentFileWith($key)

    {

        
file_put_contents($this->laravel->environmentFilePath(), preg_replace(

            
$this->keyReplacementPattern(),

            
'APP_KEY='.$key,

            
file_get_contents($this->laravel->environmentFilePath())

        ));

    }
        foreach ($files as $from => $to) {

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

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

                
file_put_contents($tofile_get_contents($from));

            }

        }
    public function activate(array $payload): void

    
{

        
file_put_contents(

            
$this->path(),

            
json_encode($payloadJSON_PRETTY_PRINT)

        );

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



        
file_put_contents($tempFile$template);



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

    }
            $body $response->getBody()->getContents();



            if (
is_string($sink)) {

                
file_put_contents($sink$body);



                return;

            }
                mkdir($directory0755true);

            }



            
file_put_contents($viewFile$contents);

        }



        return 
'__components::'.basename($viewFile'.blade.php');