執行階段的設定
php的檔案處理函數皆會受到 php.ini 裡面的設定選項影響。所以,要先了解有哪些設定:
Name | Default | Description | Changeable |
---|---|---|---|
allow_url_fopen | "1" | Allows fopen()-type functions to work with URLs (available since PHP 4.0.4) | PHP_INI_SYSTEM |
user_agent | NULL | Defines the user agent for PHP to send (available since PHP 4.3) | PHP_INI_ALL |
default_socket_timeout | "60" | Sets the default timeout, in seconds, for socket based streams (available since PHP 4.3) | PHP_INI_ALL |
from | "" | Defines the anonymous FTP password (your email address) | PHP_INI_ALL |
auto_detect_line_endings | "0" | When set to "1", PHP will examine the data read by fgets() and file() to see if it is using Unix, MS-Dos or Mac line-ending characters (available since PHP 4.3) | PHP_INI_ALL |
路徑 "/" "\" 的相容性 Unix / Windows Compatibility
Unix的路徑使用 (/),而Windows則是(/)(\) 都可以。
PHP 5 的檔案系統函數
函數 Function | 敘述 |
---|---|
basename() | 傳回一個路徑的 檔案名稱 部分 |
chgrp() | 改變檔案所屬的 群組 group |
chmod() | 改變檔案 模式 mode |
chown() | 改變檔案擁有者 file owner |
clearstatcache() | 清除檔案狀態快取 file status cache |
copy() | 複製一個檔案 |
delete() | 請閱 unlink() 或 unset() |
dirname() | 傳回一個路徑的目錄部分 Returns the directory name component of a path |
disk_free_space() | 傳回一個目錄的自由可用空間 Returns the free space of a directory |
disk_total_space() | 傳回一目錄的總共空間 Returns the total size of a directory |
diskfreespace() | 跟 disk_free_space() 一樣的。別名而已。 |
fclose() | 關閉一個開啟的檔案 |
feof() | 測試一個開啟檔案的 end-of-file |
fflush() | Flushes buffered output to an open file |
fgetc() | 傳回開啟檔案的一個字元 Returns a character from an open file |
fgetcsv() | 傳回開啟檔案的一行,CSV格式 Parses a line from an open file, checking for CSV fields |
fgets() | 傳回開啟檔案的一行 Returns a line from an open file |
fgetss() | 傳回開啟檔案的一行,移除HTML, PHP的標籤 Returns a line, with HTML and PHP tags removed, from an open file |
file() | 讀取檔案到一個陣列中 Reads a file into an array |
file_exists() | 檢查檔案或目錄是否存在 Checks whether or not a file or directory exists |
file_get_contents() | 讀取檔案進入一個字串變數 Reads a file into a string |
file_put_contents() | 將一個字串變數寫入檔案 Writes a string to a file |
fileatime() | 傳回檔案最後一次存取的時間 Returns the last access time of a file |
filectime() | 傳回檔案最後一次改變的時間 Returns the last change time of a file |
filegroup() | 傳回檔案的 群組 ID Returns the group ID of a file |
fileinode() | 傳回檔案的 inode 號碼 Returns the inode number of a file |
filemtime() | 傳回檔案最後修改的時間 Returns the last modification time of a file |
fileowner() | 傳回檔案擁有者的 user ID Returns the user ID (owner) of a file |
fileperms() | 傳回檔案的權限資料 Returns the permissions of a file |
filesize() | 傳回檔案大小 Returns the file size |
filetype() | 傳回檔案格式 Returns the file type |
flock() | 鎖定或釋放檔案 Locks or releases a file |
fnmatch() | 比對 檔案名稱或字串 Matches a filename or string against a specified pattern |
fopen() | 開啟檔案 Opens a file or URL |
fpassthru() | 讀取一個開啟的檔案,直到EOF,然後將結果寫到output buffer Reads from an open file, until EOF, and writes the result to the output buffer |
fputcsv() | 將一行格式成CSV,然後寫到開啟的檔案 Formats a line as CSV and writes it to an open file |
fputs() | 跟 fwrite()一樣 Alias of fwrite() |
fread() | 從開啟的檔案讀取 Reads from an open file |
fscanf() | Parses input from an open file according to a specified format |
fseek() | Seeks in an open file |
fstat() | Returns information about an open file |
ftell() | Returns the current position in an open file |
ftruncate() | Truncates an open file to a specified length |
fwrite() | Writes to an open file |
glob() | Returns an array of filenames / directories matching a specified pattern |
is_dir() | Checks whether a file is a directory |
is_executable() | Checks whether a file is executable |
is_file() | Checks whether a file is a regular file |
is_link() | Checks whether a file is a link |
is_readable() | Checks whether a file is readable |
is_uploaded_file() | Checks whether a file was uploaded via HTTP POST |
is_writable() | Checks whether a file is writeable |
is_writeable() | Alias of is_writable() |
lchgrp() | Changes group ownership of symlink |
lchown() | Changes user ownership of symlink |
link() | Creates a hard link |
linkinfo() | Returns information about a hard link |
lstat() | Returns information about a file or symbolic link |
mkdir() | Creates a directory |
move_uploaded_file() | Moves an uploaded file to a new location |
parse_ini_file() | Parses a configuration file |
parse_ini_string() | Parses a configuration string |
pathinfo() | Returns information about a file path |
pclose() | Closes a pipe opened by popen() |
popen() | Opens a pipe |
readfile() | Reads a file and writes it to the output buffer |
readlink() | Returns the target of a symbolic link |
realpath() | Returns the absolute pathname |
realpath_cache_get() | Returns realpath cache entries |
realpath_cache_size() | Returns realpath cache size |
rename() | Renames a file or directory |
rewind() | Rewinds a file pointer |
rmdir() | Removes an empty directory |
set_file_buffer() | Sets the buffer size of an open file |
stat() | Returns information about a file |
symlink() | Creates a symbolic link |
tempnam() | Creates a unique temporary file |
tmpfile() | Creates a unique temporary file |
touch() | Sets access and modification time of a file |
umask() | Changes file permissions for files |
unlink() | Deletes a file |
完整的刪除一個目錄:
function delTree($dir) {
- $files = glob( $dir . '*', GLOB_MARK );
- foreach( $files as $file ){
- if( substr( $file, -1 ) == '/' )
- delTree( $file );
- else
- unlink( $file );
- }
- if (is_dir($dir)) rmdir( $dir );
- }
沒有留言:
張貼留言