php implements a method to determine whether a file exists or not and then create a new one: [function mkdirs($dir, $mode = 0777){if (is_dir($dir) || @mkdir($dir, $mode) ) return TRUE;if...].
The operating environment of this article: windows10 system, php 7, thinkpad t480 computer.
We generally make a judgment before creating a file. If the file to be created exists, it will not be created. If the file to be created does not exist, it will be created. So how to implement it using php code? The following is the specific implementation code, let’s take a look.
The code is as follows:
function mkdirs($dir, $mode = 0777) { if (is_dir($dir) || @mkdir($dir, $mode)) return TRUE; if (!mkdirs(dirname($dir), $mode)) return FALSE; return @mkdir($dir, $mode); } mkdirs("aa01");
The default mode is 0777, which means the maximum possible access rights. For more information about mode please read the chmod() page.
Recommended learning: php training
The above is the detailed content of How to use PHP to determine whether a file exists or not and then create a new file. For more information, please follow other related articles on the PHP Chinese website!