Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

file_put_content create file if not exist?

Tags:

php

$html = file_get_contents('http://www.test.com);
$file = '/Applications/MAMP/htdocs/test.html';
file_put_contents($file,$html);

Does file_put_content create the file test.html when file doesn't exists?

like image 370
user3552670 Avatar asked Apr 24 '14 11:04

user3552670


People also ask

Will file_put_contents create file?

The file_put_contents() function checks for the file in which the user wants to write and if the file doesn't exist, it creates a new file.

How do you create a file in PHP If not exist?

PHP Create File - fopen() The fopen() function is also used to create a file. Maybe a little confusing, but in PHP, a file is created using the same function used to open files. If you use fopen() on a file that does not exist, it will create it, given that the file is opened for writing (w) or appending (a).

What does file_ put_ contents return?

The file_put_contents() function returns the number of bytes that were written to the file, or FALSE on failure.


1 Answers

yes.

as per php documentation:

If filename does not exist, the file is created.

like image 134
Awlad Liton Avatar answered Sep 20 '22 23:09

Awlad Liton