Skip to Content
PHP编程:第4版
book

PHP编程:第4版

by Kevin Tatroe, Peter MacIntyre
January 2021
Intermediate to advanced
505 pages
9h 45m
Chinese
Publishing House of Electronics Industry
Content preview from PHP编程:第4版
230
9
数据库
文件级别的操作
PHP
在其庞大的工具集中有很多隐藏特性。其中一个特性(经常被忽略的)就是它处理
复杂文件的可怕能力——当然,所有人都知道
PHP
可以打开文件,但是它能用文件做什
么呢?下面的例子说明了其可能性的实际应用。笔者收到一个准客户的需求,他没有钱,
但想开发一个动态网页调查系统。我首先提供给客户采用
PHP
并通过
MySQLi
进行数据
库交互的令人惊异的方案。可是当听到当地互联网服务提供商要收取的月手续费金额时,
客户询问是否有其他更便宜的方法可以完成工作。事实上,如果你不想用
SQLite
,另一
个可选的方法是用文件来管理和操作少量文本数据以备检索。我们在这里讨论的函数,
单独来看每个都是平平常常的东西——事实上,它们真的是每个人都可能很熟悉的基础
PHP
工具集的一部分,如表
9-2
所示。
9-2PHP文件管理常用函数
函数名 使用说明
mkdir()
用来在服务器上创建目录
file_exits()
用来检测指定位置的文件或目录是否存在
fopen()
用来打开存在的文件以便进行读或写(查看详细选项来正确使用它)
fread()
用来将文件内容读取到一个
PHP
使用的变量
flock()
用来获得文件的独占写锁
fwrite()
用来将变量中的内容写入文件
filesize()
当读取文件时,用来检测一次需要读取的字节数
fclose()
当文件没用时,关闭文件
有趣的部分是尝试用所有函数来实现你的目的。例如,让我们来创建一个有两页问题的
小型网页调查表单。用户可以输入一些意见,并且稍后来完成调查时,需要能正确地从 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

解密金融数据

解密金融数据

Justin Pauley
算法技术手册(原书第2 版)

算法技术手册(原书第2 版)

George T.Heineman, Gary Pollice, Stanley Selkow
Java持续交付

Java持续交付

Daniel Bryant, Abraham Marín-Pérez

Publisher Resources

ISBN: 9787121404634