
- PHP 教程
- PHP - 首頁
- PHP - 簡介
- PHP - 安裝
- PHP - 歷史
- PHP - 特性
- PHP - 語法
- PHP - Hello World
- PHP - 註釋
- PHP - 變數
- PHP - Echo/Print
- PHP - var_dump
- PHP - $ 和 $$ 變數
- PHP - 常量
- PHP - 魔術常量
- PHP - 資料型別
- PHP - 型別轉換
- PHP - 型別混合
- PHP - 字串
- PHP - 布林值
- PHP - 整數
- PHP - 檔案與 I/O
- PHP - 數學函式
- PHP - Heredoc 和 Nowdoc
- PHP - 複合型別
- PHP - 檔案包含
- PHP - 日期與時間
- PHP - 標量型別宣告
- PHP - 返回型別宣告
- PHP 運算子
- PHP - 運算子
- PHP - 算術運算子
- PHP - 比較運算子
- PHP - 邏輯運算子
- PHP - 賦值運算子
- PHP - 字串運算子
- PHP - 陣列運算子
- PHP - 條件運算子
- PHP - 展開運算子
- PHP - 空值合併運算子
- PHP - 比較運算子
- PHP 控制語句
- PHP - 決策制定
- PHP - If…Else 語句
- PHP - Switch 語句
- PHP - 迴圈型別
- PHP - For 迴圈
- PHP - Foreach 迴圈
- PHP - While 迴圈
- PHP - Do…While 迴圈
- PHP - Break 語句
- PHP - Continue 語句
- PHP 函式
- PHP - 函式
- PHP - 函式引數
- PHP - 按值傳遞
- PHP - 按引用傳遞
- PHP - 預設引數
- PHP - 命名引數
- PHP - 可變引數
- PHP - 返回值
- PHP - 傳遞函式
- PHP - 遞迴函式
- PHP - 型別提示
- PHP - 變數作用域
- PHP - 嚴格型別
- PHP - 匿名函式
- PHP - 箭頭函式
- PHP - 可變函式
- PHP - 區域性變數
- PHP - 全域性變數
- PHP 超全域性變數
- PHP - 超全域性變數
- PHP - $GLOBALS
- PHP - $_SERVER
- PHP - $_REQUEST
- PHP - $_POST
- PHP - $_GET
- PHP - $_FILES
- PHP - $_ENV
- PHP - $_COOKIE
- PHP - $_SESSION
- PHP 檔案處理
- PHP - 檔案處理
- PHP - 開啟檔案
- PHP - 讀取檔案
- PHP - 寫入檔案
- PHP - 檔案是否存在
- PHP - 下載檔案
- PHP - 複製檔案
- PHP - 追加檔案
- PHP - 刪除檔案
- PHP - 處理 CSV 檔案
- PHP - 檔案許可權
- PHP - 建立目錄
- PHP - 列出檔案
- 面向物件的 PHP
- PHP - 面向物件程式設計
- PHP - 類和物件
- PHP - 建構函式和解構函式
- PHP - 訪問修飾符
- PHP - 繼承
- PHP - 類常量
- PHP - 抽象類
- PHP - 介面
- PHP - 特性
- PHP - 靜態方法
- PHP - 靜態屬性
- PHP - 名稱空間
- PHP - 物件迭代
- PHP - 封裝
- PHP - Final 關鍵字
- PHP - 過載
- PHP - 克隆物件
- PHP - 匿名類
- PHP Web 開發
- PHP - Web 概念
- PHP - 表單處理
- PHP - 表單驗證
- PHP - 表單郵件/URL
- PHP - 完整表單
- PHP - 檔案包含
- PHP - GET 和 POST
- PHP - 檔案上傳
- PHP - Cookie
- PHP - Session
- PHP - Session 選項
- PHP - 傳送郵件
- PHP - 淨化輸入
- PHP - Post-Redirect-Get (PRG)
- PHP - 快閃記憶體訊息
- PHP 高階
- PHP - MySQL
- PHP.INI 檔案配置
- PHP - 陣列解構
- PHP - 編碼規範
- PHP - 正則表示式
- PHP - 錯誤處理
- PHP - Try…Catch
- PHP - Bug 除錯
- PHP - 適用於 C 開發人員
- PHP - 適用於 PERL 開發人員
- PHP - 框架
- PHP - Core PHP 與框架
- PHP - 設計模式
- PHP - 過濾器
- PHP - JSON
- PHP - 異常
- PHP - 特殊型別
- PHP - 雜湊
- PHP - 加密
- PHP - is_null() 函式
- PHP - 系統呼叫
- PHP - HTTP 認證
- PHP - 交換變數
- PHP - Closure::call()
- PHP - 過濾後的 unserialize()
- PHP - IntlChar
- PHP - CSPRNG
- PHP - 期望
- PHP - Use 語句
- PHP - 整數除法
- PHP - 已棄用的特性
- PHP - 已移除的擴充套件和 SAPI
- PHP - PEAR
- PHP - CSRF
- PHP - FastCGI 程序
- PHP - PDO 擴充套件
- PHP - 內建函式
- PHP 有用資源
- PHP - 速查表
- PHP - 問答
- PHP - 快速指南
- PHP - 線上編譯器
- PHP - 有用資源
- PHP - 討論
PHP 檔案系統 is_writable() 函式
PHP 檔案系統 is_writable() 函式用於檢查指定的檔案是否可寫。如果檔名存在且可寫,則此函式可以返回 true。檔名引數可以是目錄名,允許我們檢查目錄是否可寫。
- 如果失敗,則返回 E_WARNING。
- clearstatcache() 函式用於清除快取,因為此函式使用快取記憶體。
- 對於不存在的檔案,它返回 false。
語法
以下是 PHP 檔案系統 is_writable() 函式的語法 -
bool is_writable ($filename)
引數
以下是 is_writable() 函式唯一必需的引數 -
序號 | 引數和描述 |
---|---|
1 |
$filename(必填) 這是要檢查的檔案的路徑。 |
返回值
如果檔案可寫,則函式返回 TRUE,否則返回 E_Warning。
PHP 版本
is_writable() 函式最初作為核心 PHP 4 的一部分引入,並且與 PHP 5、PHP 7 和 PHP 8 相容良好。
示例
假設我們在當前工作目錄或資料夾中有一個名為 phptest.txt 的檔案。因此,我們將瞭解如何使用 PHP 檔案系統 is_writable() 函式來檢查我們的檔案是否可寫。
<?php $file = "/PhpProject/php/phptest.txt"; if(is_writable($file)) { echo ("$file is writable"); } else { echo ("$file is not writable"); } ?>
輸出
這將產生以下結果 -
/PhpProject/php/phptest.txt is writable
示例
這是另一個簡單的演示,用於瞭解 is_writable() 函式如何工作以檢查多個檔案是否可寫。
<?php $filename1 = 'myfile.txt'; $filename2 = 'index.php'; //Check that the first file is writable if(is_writable($filename1)) { echo "The first file $filename1 is writable.\n"; } else { echo "The first file $filename1 is not writable.\n"; } //Check that the second file is writable if(is_writable($filename2)) { echo "The second file $filename2 is writable.\n"; } else { echo "The second file $filename2 is not writable.\n"; } ?>
輸出
以下是以下程式碼的結果 -
The first file myfile.txt is writable. The second file index.php is not writable.
示例
在此 PHP 程式碼中,我們將使用 is_writable() 函式並檢查檔案是否可寫,我們還將顯示其許可權。
<?php // Check perm of the given file $perm = fileperms("/PhpProjects/myfile.txt"); $permValue = sprintf("%o", $perm); // Clearing the File Status Cache clearstatcache(); $filename = "/PhpProjects/myfile.txt"; // Check that the file is writable or not if(is_writable($myfile)) { echo ("The $filename is writable and it has the following file permissions : $permValue"); } else { echo ("The $filename is not writable and it has the following file permissions : $permValue"); } // Clear the File Status Cache clearstatcache(); ?>
輸出
這將生成以下結果 -
The PhpProjects/myfile.txt is writable and it has the following file permissions : 100644
注意
使用此函式,目錄的名稱也可以用作引數,這允許我們檢查目錄是否可寫或您是否沒有訪問許可權。
總結
is_writable() 方法是一個內建函式,用於檢查給定檔案是否可寫。因此,在 is_writable() 函式內部,我們可以將檔名作為引數傳遞。如果檔案具有寫許可權,則返回 True。
php_function_reference.htm
廣告