[[官方文檔-文件系統相關擴展]](http://php.net/manual/zh/refs.fileprocess.file.php)
[TOC]
## [Direct IO](http://php.net/manual/zh/book.dio.php "Direct IO")
### Direct IO 函數
This extension is only available on Windows Platforms as of PHP 5.0.0.
此擴展已被移至 [??PECL](http://pecl.php.net/) 資源庫且不再與 PHP 捆綁。5.1.0.
1. dio_close — Closes the file descriptor given by fd
2. dio_fcntl — Performs a c library fcntl on fd
3. dio_open — Opens a file (creating it if necessary) at a lower level than the C library input/ouput stream functions allow
4. dio_read — Reads bytes from a file descriptor
5. dio_seek — Seeks to pos on fd from whence
6. dio_stat — Gets stat information about the file descriptor fd
7. dio_tcsetattr — Sets terminal attributes and baud rate for a serial port
8. dio_truncate — Truncates file descriptor fd to offset bytes
9. dio_write — Writes data to fd with optional truncation at length
## [目錄](http://php.net/manual/zh/book.dir.php "目錄")
### Directory 類
1. Directory::close — 釋放目錄句柄
2. Directory::read — 從目錄句柄中讀取條目
3. Directory::rewind — 倒回目錄句柄
### 目錄函數(9個)
1. chdir — 改變目錄
2. chroot — 改變根目錄
3. closedir — 關閉目錄句柄
4. dir — 返回一個 Directory 類實例
5. getcwd — 取得當前工作目錄
6. opendir — 打開目錄句柄
7. readdir — 從目錄句柄中讀取條目
8. rewinddir — 倒回目錄句柄
9. scandir — 列出指定路徑中的文件和目錄
## [Fileinfo](http://php.net/manual/zh/book.fileinfo.php "Fileinfo")
本模塊中的函數通過在文件的給定位置查找特定的 *魔術* 字節序列 來猜測文件的內容類型以及編碼。 雖然不是百分百的精確, 但是通常情況下能夠很好的工作。
### finfo 類
1. finfo::buffer — 別名 finfo_buffer()
2. finfo::__construct — 別名 finfo_open
3. finfo::file — 別名 finfo_file()
4. finfo::set_flags — 別名 finfo_set_flags()
### fnfo 函數(6)
1. finfo_buffer — 返回一個字符串緩沖區的信息
2. finfo_close — 關閉 fileinfo 資源
3. finfo_file — 返回一個文件的信息
4. finfo_open — 創建一個 fileinfo 資源
5. finfo_set_flags — 設置 libmagic 配置選項
6. mime_content_type — 檢測文件的 MIME 類型
## [文件系統](http://php.net/manual/zh/book.filesystem.php "文件系統")
編譯此擴展無需任何額外的庫,但想要 PHP 支持 Linux 的 LFS(large files),需要最新的 glibc,并在編譯 PHP 時帶上以下標記: *\-D\_LARGEFILE\_SOURCE -D\_FILE\_OFFSET\_BITS=64*。
### 文件系統函數(80個)
1. basename — 返回路徑中的文件名部分
2. chgrp — 改變文件所屬的組
3. chmod — 改變文件模式
4. chown — 改變文件的所有者
5. clearstatcache — 清除文件狀態緩存
6. copy — 拷貝文件
7. delete — 參見 unlink 或 unset
8. dirname — 返回路徑中的目錄部分
9. disk_free_space — 返回目錄中的可用空間
10. disk_total_space — 返回一個目錄的磁盤總大小
11. diskfreespace — disk_free_space 的別名
12. fclose — 關閉一個已打開的文件指針
13. feof — 測試文件指針是否到了文件結束的位置
14. fflush — 將緩沖內容輸出到文件
15. fgetc — 從文件指針中讀取字符
16. fgetcsv — 從文件指針中讀入一行并解析 CSV 字段
17. fgets — 從文件指針中讀取一行
18. fgetss — 從文件指針中讀取一行并過濾掉 HTML 標記
19. file_exists — 檢查文件或目錄是否存在
20. file_get_contents — 將整個文件讀入一個字符串
21. file_put_contents — 將一個字符串寫入文件
22. file — 把整個文件讀入一個數組中
23. fileatime — 取得文件的上次訪問時間
24. filectime — 取得文件的 inode 修改時間
25. filegroup — 取得文件的組
26. fileinode — 取得文件的 inode
27. filemtime — 取得文件修改時間
28. fileowner — 取得文件的所有者
29. fileperms — 取得文件的權限
30. filesize — 取得文件大小
31. filetype — 取得文件類型
32. flock — 輕便的咨詢文件鎖定
33. fnmatch — 用模式匹配文件名
34. fopen — 打開文件或者 URL
35. fpassthru — 輸出文件指針處的所有剩余數據
36. fputcsv — 將行格式化為 CSV 并寫入文件指針
37. fputs — fwrite 的別名
38. fread — 讀取文件(可安全用于二進制文件)
39. fscanf — 從文件中格式化輸入
40. fseek — 在文件指針中定位
41. fstat — 通過已打開的文件指針取得文件信息
42. ftell — 返回文件指針讀/寫的位置
43. ftruncate — 將文件截斷到給定的長度
44. fwrite — 寫入文件(可安全用于二進制文件)
45. glob — 尋找與模式匹配的文件路徑
46. is_dir — 判斷給定文件名是否是一個目錄
47. is_executable — 判斷給定文件名是否可執行
48. is_file — 判斷給定文件名是否為一個正常的文件
49. is_link — 判斷給定文件名是否為一個符號連接
50. is_readable — 判斷給定文件名是否可讀
51. is_uploaded_file — 判斷文件是否是通過 HTTP POST 上傳的
52. is_writable — 判斷給定的文件名是否可寫
53. is_writeable — is_writable 的別名
54. lchgrp — 修改符號鏈接的所有組
55. lchown — 修改符號鏈接的所有者
56. link — 建立一個硬連接
57. linkinfo — 獲取一個連接的信息
58. lstat — 給出一個文件或符號連接的信息
59. mkdir — 新建目錄
60. move_uploaded_file — 將上傳的文件移動到新位置
60. parse_ini_file — 解析一個配置文件
61. parse_ini_string — 解析配置字符串
62. pathinfo — 返回文件路徑的信息
63. pclose — 關閉進程文件指針
64. popen — 打開進程文件指針
65. readfile — 輸出文件
66. readlink — 返回符號連接指向的目標
67. realpath_cache_get — 獲取真實目錄緩存的詳情
68. realpath_cache_size — 獲取真實路徑緩沖區的大小
69. realpath — 返回規范化的絕對路徑名
70. rename — 重命名一個文件或目錄
71. rewind — 倒回文件指針的位置
72. rmdir — 刪除目錄
73. set_file_buffer — stream_set_write_buffer 的別名
74. stat — 給出文件的信息
75. symlink — 建立符號連接
76. tempnam — 建立一個具有唯一文件名的文件
77. tmpfile — 建立一個臨時文件
78. touch — 設定文件的訪問和修改時間
79. umask — 改變當前的 umask
80. unlink — 刪除文件
## [Inotify](http://php.net/manual/zh/book.inotify.php "Inotify")
### Inotify 函數(5個)
類似 C 語言里的`inotify_init()` 函數會返回文件描述符,PHP 的 `inotify_init()`則返回 stream 資源。可以被標準的 Steam 函數使用,例如`stream_select()`、 `stream_set_blocking()`以及 `fclose()`。 `inotify_read()` 函數取代里 C 語言里讀取 inotify 事件的那種方式。
1. inotify_add_watch — Add a watch to an initialized inotify instance
2. inotify_init — Initialize an inotify instance
3. inotify_queue_len — Return a number upper than zero if there are pending events
4. inotify_read — Read events from an inotify instance
5. inotify_rm_watch — Remove an existing watch from an inotify instance
## [Mimetype](http://php.net/manual/zh/book.mime-magic.php "Mimetype")
This extension has been deprecated as the PECL extension [Fileinfo](http://php.net/manual/zh/book.fileinfo.php) provides the same functionality (and more) in a much cleaner way.
## [Phdfs](http://php.net/manual/zh/book.phdfs.php "Phdfs")
### phdfs類
1. phdfs::connect — Description
2. phdfs::__construct — Description
3. phdfs::copy — Description
4. phdfs::create_directory — Description
5. phdfs::delete — Description
6. phdfs::__destruct — Description
7. phdfs::disconnect — Description
8. phdfs::exists — Description
9. phdfs::file_info — Description
10. phdfs::list_directory — Description
11. phdfs::read — Description
12. phdfs::rename — Description
13. phdfs::tell — Description
14. phdfs::write — Description
## [Proctitle](http://php.net/manual/zh/book.proctitle.php "Proctitle")
This extension allows changing the current process', and thread, name on Linux and \*BSD systems. This is useful when using [pcntl\_fork()](http://php.net/manual/zh/function.pcntl-fork.php) to identify running processes in process list.
### Proctitle 函數(2個)
1. setproctitle — Set the process title
2. setthreadtitle — Set the thread title
## [xattr](http://php.net/manual/zh/book.xattr.php "xattr")
The xattr extension allows for the manipulation of extended attributes on a filesystem.
### xattr 函數(5個)
1. xattr_get — Get an extended attribute
2. xattr_list — Get a list of extended attributes
3. xattr_remove — Remove an extended attribute
4. xattr_set — Set an extended attribute
5. xattr_supported — Check if filesystem supports extended attributes
## [xdiff](http://php.net/manual/zh/book.xdiff.php "xdiff")
xdiff extension enables you to create and apply patch files containing differences between different revisions of files.
This extension supports two modes of operation - on strings and on files, as well as two different patch formats - unified and binary. Unified patches are excellent for text files as they are human-readable and easy to review. For binary files like archives or images, binary patches will be adequate choice as they are binary safe and handle non-printable characters well.
### xdiff 函數(18個)
1. xdiff_file_bdiff_size — Read a size of file created by applying a binary diff
2. xdiff_file_bdiff — Make binary diff of two files
3. xdiff_file_bpatch — Patch a file with a binary diff
4. xdiff_file_diff_binary — Alias of xdiff_file_bdiff
5. xdiff_file_diff — Make unified diff of two files
6. xdiff_file_merge3 — Merge 3 files into one
7. xdiff_file_patch_binary — Alias of xdiff_file_bpatch
8. xdiff_file_patch — Patch a file with an unified diff
9. xdiff_file_rabdiff — Make binary diff of two files using the Rabin's polynomial fingerprinting algorithm
10. xdiff_string_bdiff_size — Read a size of file created by applying a binary diff
11. xdiff_string_bdiff — Make binary diff of two strings
12. xdiff_string_bpatch — Patch a string with a binary diff
13. xdiff_string_diff_binary — Alias of xdiff_string_bdiff
14. xdiff_string_diff — Make unified diff of two strings
15. xdiff_string_merge3 — Merge 3 strings into one
16. xdiff_string_patch_binary — Alias of xdiff_string_bpatch
17. xdiff_string_patch — Patch a string with an unified diff
18. xdiff_string_rabdiff — Make binary diff of two strings using the Rabin's polynomial fingerprinting algorithm
## 備注1. php中怎么實現文件下載功能
1.直接做個超鏈接,地址為文件的地址
~~~html
<a href="文件地址">下載</a>
~~~
說明:只能下載瀏覽器不能解析的文件,比如rar啊,腳本文件之類。如果文件是圖片或者txt文檔,就會直接在瀏覽器中打開。
2.流輸出
~~~php
<?php
$file=fopen('文件地址',"r");
header("Content-Type:?application/octet-stream");
header("Accept-Ranges:?bytes");
header("Accept-Length:?".filesize('文件地址'));
header("Content-Disposition:?attachment;?filename=文件名稱");
echo?fread($file,filesize('文件地址'));
fclose($file);
?>
~~~
說明:輸出的文件流,不存在上述問題,流輸出后面不要再進行任何操作了
## 備注2. PHP通過sql生成CSV文件并下載,PHP實現文件下載
~~~php
/**
* PHP通過sql生成CSV文件并下載
* @param string $sql 查詢sql,結果為二維數組
* @param array $title 數據,CSV文件標題
* @param boolean $retuen 是否只返回數據
* @param string $filename 文件名
*/
function DownLoadCsvBySQL($sql,$title,$retuen=false,$filename='DownLoad.csv'){
$resoure = mysql_query($sql);
$data = array();
if(!$resoure) exit('Select empty!');
while($rows = mysql_fetch_assoc($resoure)) $data[] = $rows;
if($retuen) return $data;
if(empty($data)) exit('data is empty');
ob_start();
$file = fopen("php://output", 'w');
fwrite($file,chr(0xEF).chr(0xBB).chr(0xBF));
fputcsv($file, $title);
foreach($data as $k=>$v) fputcsv($file, $v);
Header("Content-type: application/octet-stream"); #通過這句代碼客戶端瀏覽器就能知道服務端返回的文件形式
Header("Accept-Ranges: bytes"); #告訴客戶端瀏覽器返回的文件大小是按照字節進行計算的
#Header("Accept-Length: ".filesize($filename)); #告訴瀏覽器返回的文件大小
Header("Content-Disposition: attachment; filename=".$filename); #告訴瀏覽器返回的文件的名稱
echo fread($file,999999);
fclose($file);
}
~~~
## 備注3. PHP實時生成并下載超大數據量的EXCEL文件
[文檔鏈接](https://segmentfault.com/a/1190000011663425)
- WebAPP
- Linux Command
- 入門
- 處理文件
- 查找文件單詞
- 環境
- 聯網
- Linux
- Linux目錄配置標準:FHS
- Linux文件與目錄管理
- Linux賬號管理與ACL權限設置
- Linux系統資源查看
- 軟件包管理
- Bash
- Daemon/Systemd
- ftp
- Apache
- MySQL
- Command
- Replication
- mysqld
- remote access
- remark
- 限制
- PHP
- String
- Array
- Function
- Class
- File
- JAVA
- Protocals
- http
- mqtt
- IDE
- phpDesigner
- eclipse
- vscode
- Notepad++
- WebAPI
- Javasript
- DOM
- BOM
- Event
- Class
- Module
- Ajax
- Fetch
- Promise
- async/await
- Statements and declarations
- Function
- Framwork
- jQurey
- Types
- Promise
- BootStrap
- v4
- ThinkPHP5
- install
- 定時任務
- CodeIgniter
- React.js
- node.js
- npm
- npm-commands
- npm-folder
- package.json
- Docker and private modules
- module
- webpack.js
- install
- configuration
- package.json
- entry
- modules
- plugins
- Code Splitting
- loaders
- libs
- API
- webpack-cli
- Vue.js
- install
- Compile
- VueAPI
- vuex
- vue-router
- vue-devtools
- vue-cli
- vue-loader
- VDOM
- vue-instance
- components
- template
- Single-File Components
- props
- data
- methods
- computed
- watch
- Event-handling
- Render Func
- remark
- 案例學習
- bootstrap-vue
- modal
- fontAwesome
- Hosting Font Awesome Yourself
- using with jquery
- using with Vue.js
- HTML
- CSS
- plugins
- Chart.js
- D3.js
- phpSpreadSheet
- Guzzle
- Cmder
- Git
- git命令
- git流程
- Postman
- Markdown
- Regular Expressions
- PowerDesigner
- 附錄1-學習資源