Home  >  Article  >  Backend Development  >  What should I do if php cannot create a directory?

What should I do if php cannot create a directory?

藏色散人
藏色散人Original
2022-10-20 17:34:192183browse

Solution to the problem that php cannot create a directory: 1. Open and check the corresponding PHP code file; 2. Check whether the created directory exists in a multi-level directory; 3. Add the third parameter to the mkdir function. Turn on recursive mode, its syntax is like "mkdir($uploadpath,0777,true)".

What should I do if php cannot create a directory?

The operating environment of this tutorial: Windows 7 system, PHP version 8.1, Dell G3 computer.

In PHP programming, you often encounter file uploading, folder creation, etc. A very important function will be used: mkdir; its function is to create a directory to store the folder for uploaded files. If the creation of multi-level directories is involved during the upload process, errors are often encountered. How to deal with it?

php file upload class; PHP development and running environment.

Upload, folder creation failed:

What should I do if php cannot create a directory?

Check the function description in the official PHP documentation:

What should I do if php cannot create a directory?

mode has been specified as: 0777. Why is it still reporting an error saying that it does not have permission? ?

After carefully reading the document, I found that this involves a recursive mode, and the directories that may be created exist in multi-level directories. The current directory to be created in the project: 20160704, it should be in the online/thum/img folder:

What should I do if php cannot create a directory?

So, add the third parameter to the mkdir function to open Recursive mode:

Example: mkdir($uploadpath,0777,true);

What should I do if php cannot create a directory?

Upload the image again, successful! !

What should I do if php cannot create a directory?

Recommended study: "PHP Video Tutorial"

The above is the detailed content of What should I do if php cannot create a directory?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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