Home  >  Article  >  Backend Development  >  What to do if php mkdir fails

What to do if php mkdir fails

藏色散人
藏色散人Original
2020-08-12 10:07:484291browse

php The solution to the failure of mkdir: first log in to the server; then authorize the directory where the folder is to be created as "chmod 777 parpath" under root; and finally run the mkdir code.

What to do if php mkdir fails

Recommended: "PHP Video Tutorial"

Solution to PHP mkdir failure under Linux

I recently made a website, and the user needed to manually create folders in the background. After the website was written, it ran very well under Windows, but something went wrong as soon as the results were uploaded to the server. After manually creating When entering the folder, no error is reported, but when I enter that directory, I cannot see the corresponding folder created. There must be a problem with the code execution. The code is as follows:

mkdir($path,0777);
if(file_exists($path))
      echo "目录创建成功!";
else
      echo "创建目录失败!";

I suspected it was a permissions issue, so I logged in to the server and authorized the directory where the folder was to be created under root: chmod 777 parpath, and then ran the code, everything was ok!

Note: parpath is the parent directory and path is the subdirectory to be created.

  • mkdir() function creates a directory.

This function returns TRUE if successful and FALSE if failed.

Grammar

mkdir(path,mode,recursive,context)

The above is the detailed content of What to do if php mkdir fails. 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