What to do if the php fopen file does not exist

藏色散人
Release: 2023-03-10 16:12:01
Original
2467 people have browsed it

php fopen file does not exist solution: first create a PHP sample file; then use the "if (!function_exists('mkdirs')) {...}" method to determine whether the folder exists, if not, then Just create a new one.

What to do if the php fopen file does not exist

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

What should I do if the php fopen file does not exist?

Determine whether the folder exists in php. If it does not exist, create a new one.

Introduction: During the project development process, sometimes it is necessary to read or generate files in the specified folder. At this time, you need to first determine whether the folder exists, and if it does not exist, create a new one.

Method:

//判断文件夹是否存在,没有则新建。 if (!function_exists('mkdirs')) { 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); } }
Copy after login

Actual use:

//判断文件夹是否存在 public function test() { $localhost_path = ROOT_PATH . 'public/static/unit_record/'; $result = mkdirs($localhost_path);//这里会返回true }
Copy after login

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What to do if the php fopen file does not exist. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!