Caution </ b>: This article is for making security changes. We are not responsible for any problems or damages caused by this article, so please be sure to be sure to do so within your own responsibility </ b> when executing commands. I will. </ font>
file_put_contents ()
→ Adds contents to the file with the specified path when PHP is executed.
file_get_contents ()
→ When PHP is executed, the contents of the file with the specified path are called.
Permission
→ Permission to operate directories and files. (Recursive in Japanese)
The other day, when I was learning PHP, I had a scene where I used file_put_contents ()
and file_get_contents ()
, but I got hooked there, so I will leave a solution.
In conclusion, it was a Permission
problem.
I'm using MacOS, so first open a terminal. Next, move up one level in the directory where you want to check Permission
, and enter the following command.
$ ls -la
Then, the following notation will appear in a row for each directory and file.
drwxrwxrwx 1 username admin 1918 4 21 14:22 example.html
The leftmost column shows the Permission
of the directory or file displayed on the right. (Other than that, you don't have to worry too much.)
The leftmost d seems to be complicated, so ignore it, and the important part is the part where three rwx
s continue.
$ chmod 765
First, type chmod (change mode)
to make Permission change </ b> possible. Then you can change the Permission
of all directories and files under the current directory by entering any number </ b> and executing.
By the way, arbitrary numbers </ b> can be determined as follows.
rwx rwx rwx | r-- -w- --x | rwx rw- r-x |
---|---|---|
↓ ↓ ↓ | ↓ ↓ ↓ | ↓ ↓ ↓ |
7 7 7 | 4 2 1 | 7 6 5 |
↓ | ↓ | ↓ |
777 | 421 | 765 |
If you want to change the Permission
of any directory or only the file specified here instead of changing all the Permission
under the current directory, execute the following command.
$ chmod 765 example.html
In this case, change Permission
of example.html
under the current directory to 765 </ b>.
In my case, I could change the Permission
of only one file like this to allow the execution offile_put_contents ()
andfile_get_contents ()
, which was the problem this time, and solve it. I did.
This is a list of commands introduced this time.
$ ls -la
$ chmod 765
$ chmod 765 example.html
Again, the Permission
setting is an important security-related setting </ b>, so carefully when changing . / b> Please go. </ font>
Thank you for reading until the end!
Recommended Posts