创建一个php文件

Is there any script that can make a file in a directory specified? like

<?php

createfile("hi.txt","/home/public_html/files");

?>

You can use file_put_contents.

<?php

file_put_contents("/home/public_html/files/hi.txt", "content");

?>

Or touch if you don't need the content and just want to be sure the file is created:

<?php

touch("/home/public_html/files/hi.txt");

?>

yes file_put_contents()

file_put_contents("/home/public_html/files/hi.txt",$data);

You can/should use native PHP function:

file_put_contents('/home/public_html/files/hi.txt', 'lorem ipsum')

http://php.net/manual/en/function.file-put-contents.php

Also try fopen("/path/to/file", 'w')

"w" will according to the docs "If the file does not exist, attempt to create it. "

Maybe this is for some people asking whether to use file_put_contents() or touch().

Simply:

fwrite($file = fopen($filename, "w"), "New content");
fclose($file);

If file doesn't contain any contents:

fclose($file = fopen($filename, "w"));

Also, check if file exists with file_exists() to prevent clearing contents of an existing file:

if (!file_exists($filename))
    fclose($file = fopen($filename, "w"));