


Complete file operations in one day and related operations of reading files (with detailed explanation)
The previous article introduced you to "5 minutes to understand what is a file system?" What types of functions do they need to create? 》, this article will continue to introduce to you the related operations of reading files after finishing the file operation in one day, let’s work hard together! ! !
Whether the file is executable:
- is executable()
Whether the file is readable:
is readable()
Whether the file is writable:
is writable()
Creation time of the employment file:
filectime()返回创建时间的时间戳
Modification time of the employment file:
一filemtime()
Last access time of the obtained file:
- fileatine()
flock simple file lock
Modification time of the obtained file
filemtime()
Get the file last access time
fileat: ime()
flockSimple file lock
Open file
fopen()
Parameter: The path of the file to be opened
Parameter: The way to open the file r Open the file in read-only mode
Return value: Return the resource successfully, return false
Close the file:
fclose()
Parameter: the resource returned by fopen successfully opening the file
Read the file
fread()读取文件
Parameter 1: The resource returned by fopen successfully opening the file
Parameter 2: The number of bytes to be read
Return: Return the read content, if it is read to the end Returns the null character.
feof() determines whether the file pointer has reached the end
Parameter 1: The resource returned by fopen successfully opening the file
Return value: If the file Returns true when the pointer reaches the end or an error occurs, returns false when it does not reach the end;
fgets() reads lines from the file pointer
Parameter 1: succeeded by fopen Resources returned by opening the file
Return value: Return the read content
We use code to demonstrate opening the file. First, our function to open the file is fopen(). When we open the file, There is a return value. When we run the result, we find that we are missing the second parameter and the Boolean value reported is: false. That is to say, we can open the file, but we have to tell how to open the file. We are reading. Open or open by writing, so we now open it by reading (the code is as follows). After the code is written, the running result shows that it was successfully opened;
For closing the file: we use fclose() function, if we directly use the fclose function to demonstrate the results, an error will appear, and a parameter will be missing, so we need to specify which parameter to close.
<?php /**** *打开文件读取文件 关闭文件*********/ $file = fopen('./a.txt','r'); var_dump($file); //关闭文件 fclose($file); ?>
When we want to read a file, we need to use the fread() function. After reading, it will return the read content, and then we print out ($content), and we will find that running The result is wrong again, one parameter is still missing
<?php /*****打开文件读取文件关 闭文件*********/ $file = fopen(' ./a.txt','r'); //var_ dump($file); //读取文件内容 $content = fread($file,1); var_ dump($content); //关闭文件 fclose($file);
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of Complete file operations in one day and related operations of reading files (with detailed explanation). For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Reading and writing files safely in Go is crucial. Guidelines include: Checking file permissions Closing files using defer Validating file paths Using context timeouts Following these guidelines ensures the security of your data and the robustness of your application.

A gho file is an image file created by NortonGhost software and used to back up and restore the operating system and data. In some cases, you can delete gho files, but do so with caution. This article will introduce the role of gho files, precautions for deleting gho files, and how to delete gho files. First, let's understand the role of gho files. A gho file is a compressed system and data backup file that can save an image of an entire hard disk or a specific partition. This kind of backup file is usually used for emergency recovery

With the continuous development of web applications, PHP has become one of the most important programming languages in web development. As an extremely flexible programming language, each version of PHP brings new features and optimizations to meet different needs and application scenarios. In the PHP8.0 version, a very practical file operation function has been added, namely file monitoring. This function is very suitable for application scenarios that require monitoring and processing of file changes, such as file backup, file synchronization, log monitoring, etc. This article will take you

How to solve: Java file operation error: File writing failed. In Java programming, you often encounter the need for file operations, and file writing is one of the important functions. However, sometimes we encounter file writing failure errors, which may prevent the program from running properly. This article will describe some common causes and solutions to help you solve this type of problem. Wrong path: A common problem is wrong file path. When we try to write a file to the specified path, if the path does not exist or the permissions are insufficient, the file will be written.

The Go language provides two methods to clear file contents: using io.Seek and io.Truncate, or using ioutil.WriteFile. Method 1 involves moving the cursor to the end of the file and then truncating the file, method 2 involves writing an empty byte array to the file. The practical case demonstrates how to use these two methods to clear content in Markdown files.

PHP is a popular programming language widely used in web development. In web applications, file operations are a basic and common function. This article will explain how to use PHP to read a CSV file and display it in an HTML table. CSV is a common file format used to import tabular data into spreadsheet software such as Excel. CSV files usually consist of many lines, each line consisting of comma separated values. The first line usually contains column headers, which describe the meaning of each column value. Here we will use PHP

Learn the file operation functions in Go language and implement the encryption, compression, upload and download functions of files. Go language is an open source statically typed programming language. It is widely popular in the development field for its efficient performance and concise syntax. The standard library of the Go language provides a wealth of file operation functions, making it very simple to read and write files, encrypt and compress them, upload and download them. This article will introduce how to use the file operation functions in the Go language to implement the functions of encrypting, compressing, uploading and downloading files. First, we need to import the relevant three

In C++, use the ofstream class to insert content at a specified location in a file: open the file and locate the insertion point. use
