Home >Backend Development >PHP Problem >What should I do if php cannot create a directory?
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)".
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:
Check the function description in the official PHP documentation:
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:
So, add the third parameter to the mkdir function to open Recursive mode:
Example: mkdir($uploadpath,0777,true);
Upload the image again, successful! !
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!