PHP文件处理
这是我在学习php过程中做的笔记,为了可以有一个良好的学习习惯,也为了给广大的编程爱好者一个学习的参考,特把学习笔记分享出来,希望对自己和大家都有帮助。本学习资料主要来自于LAMP兄弟连的细说PHP,PHP5中文手册和网上资料,强烈推荐有志于学习PHP的朋友选择LAMP兄弟连的《细说PHP》
文件判断函数
is_dir()
is_executable() 判断是否是可执行文件
is_file()
is_link() 判断文件名是否为一个符号连接
is_readable()
is_uploader_fiel() 判断文件是否通过HTTP POST上传
is_writable()
文件属性
file_exists()
filesize()
is_readable()
is_writeable()
filectime()
filemtime()
取文件名 basename()
取目录 dirname()
文件路径信息 pathinfo()
创建文件 touch($file)
删除文件 unlink($file)
移动文件(重命名文件) rename(“当前文件路径","目标文件路径")
复制文件 copy(“文件名",”路径")
读写文件
file_get_contents()
file_put_contents()
fopen(“URL”,模式)
各种模式:
r: 只读模式打开文件 r+:读写模式 w: 只写模式打开,若文件不存在,则新建,若文件已有内容,则覆盖 w+ :读写模式 a: 只写模式打开,若文件不存在,则新建,若文件已有内容,则追加 a+:读写模式 b :以二进制模式打开文件(图片,视频) t :以文本模式打开文件fread() //读取指定长度的字符;fread(“$file”,filesize(“text.txt”))
fgetc() //一次从文件中读取一个字符;
fgets() //一次从文件中读取一行字符;
feof($file) //读取文件出错或到文件结束则返回真
写入文件
fwrite()
文件内部移动指针
ftell($file) //返回当前指针位置
fseek($file,100,常量) //移动文件指针
rewind()
basename(文件路径[,文件后缀名]) 获取文件名,第二个参数为获取文件基本名称 pathinfo(文件路径) 分析当前路径,返回一个关联数组,通过dirname,basename,extension来引用 realpath(文件相对路径) 显示文件绝对路径 filesize($file) 计算文件大小 fileatime($file) 显示最后一次被访问的时间 filectime($file) 文件建立时间 filemtime($file) 文件最后一个更新 fileperms() 返回文件属性以及权限 fileowner() 取得文件所有者
目录操作:
opendir() readdir() closedir() rewinddir() //指针返回第一个目录
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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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

The CSV (Comma-SeparatedValues) file format is widely used for data exchange and import/export jobs. In PHP, CSV files can be easily created using the built-in file manipulation functions and CSV functions. In this article, we will learn how to create CSV files using PHP. Step 1: Create a CSV file. To create a CSV file, you first need to open a file handle and set the file's opening mode. In this example, we open the file for writing, and if the file does not exist,

Getting Started with PHP File Handling: In-depth Understanding of the Basic Steps of Reading and Writing File handling is a very common and important task in PHP development. Whether it is reading the contents of a file or writing data to a file, it can be achieved through the built-in functions provided by PHP. This article will introduce the basic steps of PHP file processing and provide some code examples for reference. 1. Basic steps for reading files Reading files is an operation we often need to perform when processing files. Here are the basic steps for reading a file: use fopen(

In the Internet era, file operations have become one of the most common operations for programmers. As a popular server-side scripting language, PHP also has powerful file operation functions. This article will introduce how to perform file operations in PHP7.0, including operations such as opening, reading, writing, closing, and deleting files. At the same time, we will also introduce some common file processing functions to help readers better use PHP for file operations. Opening files In PHP, our commonly used file opening function is fopen(). This function requires two

How to handle file reading, writing and directory operations in PHP? As a widely used server-side scripting language, PHP plays an important role in web development. In many projects, we need to read, write and directory operations on files in order to store and manage data. This article will introduce common methods and techniques on how to handle file reading, writing and directory operations in PHP. 1. File read and write operations. Opening and closing files. To read and write files, you first need to use the fopen function to open the file. This function needs to receive two parameters.

Getting Started with PHP File Handling: Detailed Basic Steps for Reading and Writing Overview: Processing files is a very common task in web development. As a powerful server-side scripting language, PHP provides a wealth of file processing functions and methods, which can easily read and write file contents. This article will introduce the basic steps of reading and writing files using PHP and provide corresponding code examples. Reading file contents: Reading file contents is one of the common file processing tasks. PHP provides multiple functions and methods to achieve this

Summary of PHP file processing experience: Tips and experiences for achieving efficient reading and writing In web development, file processing is a common task. Whether reading configuration files or writing files uploaded by users, handling files is an essential skill for PHP programmers. This article will share some tips and experiences for achieving efficient reading and writing, and use code examples to deepen understanding. Reading files Reading files is one of the common operations. Here are several common methods for reading files: 1.1file_get_con

PHP is a high-level programming language widely used in website development and back-end services. As developers, we need to handle a large number of files, such as reading and writing files, creating directories, deleting files, etc. In this article, we will introduce you to some common operations and techniques of PHP file processing functions to help developers better process files. 1. File processing function fopen(): opens a file and returns a file pointer, which can be used to read or write files. fclose(): Close an open file pointer. fread

How to use file and directory handling functions in PHP? In web development, working with files and directories are common tasks. PHP provides a series of file and directory processing functions, allowing developers to easily operate files and directories. First, let's look at how to create, delete, and write files. Creating a File Use PHP's file_put_contents function to write contents to a file and create a new file. The following is a sample code: $file='test.txt';
