PHP supports the control of various types of databases, and also has rich control methods for files, many of my friends are still holding files based on files, but sometimes there are still a lot of puzzles and doubts when holding files.
Preface:
PHP supports the control of various types of databases, and also has rich control methods for file control, many of my friends are still holding files based on files, but sometimes there are still a lot of puzzles and doubts when holding files, the following are some of the titles about file control that I encountered during my daily writing and some of my friends encountered on the altar.
Q: How to create a file?
A:
1. apply fopen (name of the file to be created, parameter). optional values: w, w, a, and.
2. apply exec (echo ''> file name to be created). In this way, you can use the linux command touch to create this file.
Q: Why cannot I create a file?
A:
1. if you have applied fopen to create a file, is the parameter applied accurately?
2. system permission Title. please ask your WEBMASTER if your FTP directory has write permission
3. for the title of the FTP permission, make sure that you have the write permission in the directory where the file to be written in your php file is located, that is, the other group must have the write permission after your FTP software logs in, if you do not have the permission, correct the permission and try again.
Q: How do I read files into an array?
Answer: apply the file function.
Q: How can I read all files?
A:
1. apply fread ($ fp );
2. if your PHP version is> = 4.3.0, you can apply file_get_contents ();
Q: How can I determine whether a file exists?
A: apply file_exists ();
Q: Why not use fopen () to determine it?
A: The reason is that sometimes the title of the permission causes the data returned by fopen to lead our incorrect determination.
Q: Why does an error occur when I read a web page?
A:
1. it may be your passing Parameter error. when reading the web page, you can only use the r method to read the page.
2. make sure that you can visit the WEB page you want to read
Q: How can I obtain the relevant attributes of a file?
A: PHP provides a set of methods to obtain file attributes, such as filemtime (), fileowner (), filegroup (), filectime (), fileatime ()... for specific applications, see the manual.
Q: Can I locate the file "cursor" like C after opening the file in PHP?
A: Yes. use fseek ();
Q: What should I do if I don't promise anyone else to visit this file?
A:
1. you can use other programs to restrict users from accessing the file control page.
2. apply flock (). For detailed parameters and application methods, see the manual.
Q: How do I delete the first row of data in a file or specify a row of data?
A:
PHP does not provide such a control method, but we can apply it in combination. the following code demonstrates that we will delete the third row of data in the test. dat file (more than three rows of data in the test. dat file)