FAQs about file control in PHP development

Source: Internet
Author: User
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)

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.