Home  >  Article  >  Backend Development  >  How to solve the problem of php mkdir failure under Linux

How to solve the problem of php mkdir failure under Linux

藏色散人
藏色散人Original
2020-07-24 10:54:593059browse

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

How to solve the problem of php mkdir failure under Linux

Recommended: "PHP 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. However, as soon as the results were uploaded to the server, something went wrong. After manually creating the files, When entering the folder, no error is reported, but when entering 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.

The above is the detailed content of How to solve the problem of php mkdir failure under Linux. 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