PHP operation file Q &

Source: Internet
Author: User
Tags manual php file first row
PHP operation file Q &
Preface:
PHP supports operations on various types of databases, and also provides rich operation methods for file operations, many of my friends are still operating on files, but sometimes there are still many puzzles and doubts when operating on files, the following are some of the file operations problems I encountered during my daily writing and my friends encountered on the altar.
Q: How to create a file?
A:
1. Use fopen ("name of the file to be created", "parameter"). Optional values include w, w +, a, and a +.
2. Use 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 use fopen to create a file, is the parameter used correctly?
2. For system permission questions, please ask your WEBMASTER if your FTP directory has write permission
3. For FTP permissions, 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, modify the permission and try again.
Q: How do I read files into an array?
A: use the file function.
Q: How can I read all files?
A:
1. Use fread ($ fp );
2. If your PHP version is> = 4.3.0, you can use file_get_contents ();
Q: How can I determine whether a file exists?
A: use file_exists ();
Q: Why not use fopen () for determination?
A: The reason is that sometimes the data returned by fopen leads us to wrong judgments due to permission issues.
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 read the page in r mode.
2. Make sure that the WEB page you want to read can be accessed
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 more information, 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 allow others to access this file?
A:
1. You can use other programs to restrict access to file pages.
2. Use flock (). For detailed parameters and usage instructions, 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 an operation method, but we can use it in combination. The following code demonstrates that we will delete the file "test. the third row of data (test. there are more than three rows of data in the dat file)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.