PHP操作文件常用函数
1、函數功能簡述
-
fopen() 打開文件或者 URL
鏈接:https://www.php.net/fopen -
fsockopen() 打開一個網絡連接或者一個Unix套接字連接
鏈接:https://www.php.net/fsockopen -
fwrite() 寫入文件
鏈接:https://www.php.net/fwrite -
basename() 返回路徑中的文件名部分。
鏈接:https://www.php.net/basename -
**copy()**復制文件
鏈接:https://www.php.net/copy -
dirname() 返回路徑中的目錄部分
鏈接:https://www.php.net/dirname -
disk_free_space() 返回目錄中的可用空間
鏈接:https://www.php.net/disk_free_space -
disk_total_space() 返回一個目錄的磁盤總大小
鏈接:https://www.php.net/disk_total_space -
fclose() 關閉一個已打開的文件指針
鏈接:https://www.php.net/fclose -
feof() 測試文件指針是否到了文件結束的位置
鏈接:https://www.php.net/feof -
fgetc() 從文件指針中讀取一個字符
鏈接:https://www.php.net/fgetc -
fgets() 從文件指針中讀取一行
鏈接:https://www.php.net/fgets -
fgetss() 從打開的文件中讀取一行并過濾掉 HTML 和 PHP 標記。
鏈接:https://www.php.net/fopen -
file() 把整個文件讀入一個數組中
鏈接:https://www.php.net/file -
file_exists( string $filename ) : bool 檢查文件或目錄是否存在
鏈接:https://www.php.net/file_exists -
file_get_contents() 將整個文件讀入一個字符串
鏈接:https://www.php.net/file_get_contents -
file_put_contents() 將一個字符串寫入文件
鏈接:https://www.php.net/file_put_contents -
filesize() 函數返回指定文件的大小 ,返回字節數
鏈接:https://www.php.net/filesize -
filetype() 返回指定文件或目錄的類型。
鏈接:https://www.php.net/filetype -
flock() 鎖定或釋放文件
鏈接:https://www.php.net/flock -
unlink() 刪除文件
鏈接:https://www.php.net/unlink -
fgetcsv() 從文件指針中讀入一行并解析 CSV 字段
鏈接:https://www.php.net/fgetcsv -
fputcsv() 將行格式化為 CSV 并寫入文件指針
鏈接:https://www.php.net/fputcsv -
fpassthru() 函數輸出文件指針處的所有剩余數據
鏈接:https://www.php.net/fpassthru -
parse_ini_file() 函數解析一個配置文件,并以數組的形式返回其中的設置。
鏈接:https://www.php.net/parse_ini_file -
pathinfo() 以數組的形式返回文件路徑的信息
鏈接:https://www.php.net/pathinfo -
realpath() 返回文件的絕對路徑
鏈接:https://www.php.net/realpath -
rename() 函數重命名文件或目錄
鏈接:https://www.php.net/rename -
mkdir() 創建目錄
鏈接:https://www.php.net/mkdir -
move_uploaded_file() 將上傳的文件移動到新位置
鏈接:https://www.php.net/move_uploaded_file -
rmdir() 刪除空目錄
鏈接:https://www.php.net/rmdir -
touch() 設置指定文件的訪問和修改時間
鏈接:https://www.php.net/touch -
unlink() 刪除文件
鏈接:https://www.php.net/unlink -
fseek() 在打開的文件中定位
鏈接:https://www.php.net/fseek -
rewind() 將文件指針的位置倒回文件的開頭。
鏈接:https://www.php.net/rewind -
glob() 尋找與模式匹配的文件路徑
鏈接:https://www.php.net/glob -
scandir() 列出指定路徑中的文件和目錄
鏈接:https://www.php.net/scandir -
opendir() 打開目錄
鏈接:https://www.php.net/opendir -
readdir() 獲取打開目錄中的一條子目錄/文件名稱
鏈接:https://www.php.net/readdir -
closedir(); 關閉目錄
鏈接:https://www.php.net/closedir -
is_dir() 判斷指定的文件名是否是一個目錄。
鏈接:https://www.php.net/is_dir -
is_executable() 判斷文件是否可執行。
鏈接:https://www.php.net/is_executable -
is_file() 判斷指定文件是否為常規的文件。
鏈接:https://www.php.net/is_file -
is_link() 判斷指定的文件是否是連接。
鏈接:https://www.php.net/is_link -
is_readable() 判斷文件是否可讀。
鏈接:https://www.php.net/is_readable -
is_uploaded_file() 判斷文件是否是通過 HTTP POST 上傳的。
鏈接:https://www.php.net/is_uploaded_file -
is_writable() 判斷文件是否可寫。
鏈接:https://www.php.net/is_writable
詳細的內容參考 https://www.php.net/ ,其中想要參考的函數在后面斜杠加上去就可以了。
例如:我想查看 is_dir() 函數,只需要在鏈接后面加上即可 https://www.php.net/is_dir 。
總結
以上是生活随笔為你收集整理的PHP操作文件常用函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PHP爬取企业详情(百度信用)
- 下一篇: TP5 实现微信支付和支付宝支付