search
HomeBackend DevelopmentPHP ProblemWhat should I do if php cannot write files?

Solution to the problem that php cannot write files: 1. Use an absolute path, such as "dirname(__FILE__)."/logs/test.log""; 2. Use the chmod command to change other permissions of the file to Writable.

What should I do if php cannot write files?

The operating environment of this article: linux5.9.8 system, php5 version, DELL G3 computer

What should I do if php cannot write files?

Solution to the problem that php cannot create or write files under Linux

Environment Apache/2.4.7 php5

There are only two reasons for file writing errors: path problems or Permissions issue.

Regarding the path problem, you can output your own path to see if it is correct. It is recommended to use an absolute path, such as dirname(__FILE__)."/logs/test.log".

There are many possibilities for permission issues. I will only talk about my own problems here. Since I create the file first, I must set other permissions of the folder where the created file belongs to be writable, that is, the rightmost w in drwxrwxrwx is required. The default permissions of the files created at this time are as follows

The group and user to which they belong are www-data, and the permissions are 644.

Another reason may be that the file you created through the command line cannot be written. For example, the current user is root and I created a file through the command line. The default permissions of the file are not writable by other users. The solution is to use the chmod command to change the other permissions of the file to be writable.

Recommended Study: "PHP Video Tutorial"

The above is the detailed content of What should I do if php cannot write files?. 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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor