Some FAQ summary on PHP operation files

xiaoxiao2021-03-06  39

Preface: There is support for the operation of various databases in PHP, and the operation of the file is also a rich operation method. Many friends now operate on the file operation, but there is still a lot of confusion when operating the file. And doubts, the following is some of my questions about documentation, and some questions that I have encountered during the day-to-day writing process and the documents.

Q: How to create a new file?

A: 1. Use Fopen ("File Name", "Parameters"), parameter), parameter options W, W , A, A 2, using EXEC ("Echo ''" to be established file name "); this is Use the system to establish this file, you can also use the touch command to build

Q: Why can't I create a file?

A: 1. If you use the FOpen to build a file, whether you use the parameter 2, system permission issues, please ask your webmaster's FTP directory whether you have written permissions 3, FTP permission, you have to confirm your PHP The file must write the authority to write the file, that is, your FTP software logs in, the Other group has to write this permission. If you do not have the right to modify the permissions, try

Q: How do I read the file into an array?

A: Using File

Q: How do I read all the files?

A: 1. Use Fread ($ fp); 2. If your PHP version> = 4.3.0 can be used, you can use file_get_contents ();

Q: How do I determine if the file exists?

A: Use file_exists (); why not use fopen () to determine? The reason is sometimes because the permissions have caused the data returned by the FOPEN to guide us the wrong judgment.

Q: Why did you make an error when I read a web page?

A: 1, maybe your pass parameters wrong, you can only read the page 2 when reading the web page, make sure you want to read the web page to access

Q: How can I get the relevant properties of the file?

A: PHP provides a group of methods for obtaining file properties, such as FilemTime (), Fileowner (), FileGroup (), Filectime (), FileAtime () ... Detailed UFUSE TECHET.

Q: Can the PHP open the file "Cursor" in the file?

A: Yes, use fseek ();

Q: What should I do if I don't allow other people to access this file when I have access to the file?

A: 1. You can use other aspects to limit the page 2 of the user access file operation, use flock (); detailed parameters and methods of use, please refer to the manual

Q: How do I delete the first line in the file or specify a line of data?

A: PHP does not provide this way of operation, but we can use the following code demonstrate that we will delete the third line of data in the file "Test.dat" (more than three lines in the Test.datw file)

Q: When I tried to open a file that did not exist, I didn't let the error showed it to avoid my path to disclose! !

A: Add @ symbol to block errors before you want to open the file, @ is a dedicated symbol of the error information shield provided by PHP

Or you can increase before this step (usually on page) Error_Reporting (0); display to block all error messages in the page

A unkreated method is to modify php.ini (except ISP)

Q: I am using a virtual host, how do I prevent other users from stealing my data?

A: It is recommended that ISP modifies the Open_BASEDIR in php.ini to limit,

The unhefetried ISP settings add file operations such as FOPEN, FILE to disable_function.

Q: Why did I use a PHP to build a file I want to delete these files can't be deleted? ?

A: It is mainly because PHP is owned by the web user group, which is also the created file, not your FTP user! ! !

The solution to this problem is to process using a PHP program's ChMOD, UNLINK, etc. It is recommended that users remember Chmod file permissions when using PHP to establish files. It is recommended to ask 777: How to use text files as a data warehouse? Some message books, the forums are used to use this!

A: In fact, this mainly uses File, combined with Explode to read and split typical examples.

Q: How do I change the file name?

A: rename ();

Q: How do I delete a file?

A: unlink (); Exec ("DEL (RM -VF) filename"); Note: RM -VF is used under Linux

Q: How to empty a file?

A: Using Fopen (FileName, "W"); or Exec ("Echo ''> FileName");

Q: How do I edit the contents of the file?

转载请注明原文地址:https://www.9cbs.com/read-70600.html

New Post(0)