You can use a higher-level function like:
file_put_contents($filename, $content);
which is identical to calling fopen(), fwrite(), and fclose() successively to write data to a file.
Docs: file_put_contents
More Related Contents:
- Adding files cookies PHP (host)
- How do I save the output of this code into a file? (PHP) [closed]
- How do I add PHP code/file to HTML(.html) files?
- How can one check to see if a remote file exists using PHP?
- Getting the names of all files in a directory with PHP
- How to delete a line from the file with php?
- PHP, get file name without file extension
- Reading very large files in PHP
- Encrypting / Decrypting file with Mcrypt
- PHP script to loop through all of the files in a directory?
- PHP list of specific files in a directory
- How do I prepend file to beginning?
- Get the current script file name
- Efficiently counting the number of lines of a text file. (200mb+)
- PHP: How to check if image file exists?
- php glob – scan in subfolders for a file
- HTTP requests with file_get_contents, getting the response code
- Least memory intensive way to read a file in PHP
- How to limit file upload type file size in PHP?
- PHP: Force file download and IE, yet again
- Laravel 5.3 multiple file uploads
- PHP see only 20 uploading files at a time
- overriding upload_max_filesize
- Create new XML file and write data to it?
- Get the hierarchy of a directory with PHP
- move all files in a folder to another?
- Read and write to a file while keeping lock
- PHP Undefined index error $_FILES?
- php script to delete files older than 24 hrs, deletes all files
- How to execute and get content of a .php file in a variable?