php opendir 開啟目錄函式

來源:互聯網
上載者:User

php opendir 開啟目錄函式

PHP 4中,PHP 5中)

opendir - 開啟目錄控制代碼

報告錯誤描述
資源opendir(字串$路徑[,資源$背景])
開闢了一個目錄控制代碼將用於隨後的closedir(),readdir()和rewinddir()調用。

定義和用法
opendir() 函數開啟一個目錄控制代碼,可由 closedir(),readdir() 和 rewinddir() 使用。

若成功,則該函數返回一個目錄流,否則返回 false 以及一個 error。可以通過在函數名前加上 "@" 來隱藏 error 的輸出。


報告錯誤參數

路徑
目錄路徑是要開啟

上下文
對於內容相關的參數的說明,請參閱手冊中的流部分。

<?php
$dir = "/etc/php5/";

// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
    if ($dh = opendir($dir)) {
        while (($file = readdir($dh)) !== false) {
            echo "filename: $file : filetype: " . filetype($dir . $file) . "n";
        }
        closedir($dh);
    }
}
?>
The above example will output something similar to:

filename: . : filetype: dir
filename: .. : filetype: dir
filename: apache : filetype: dir
filename: cgi : filetype: dir
filename: cli : filetype: dir

 

報告錯誤傳回值
返回目錄控制代碼失敗資源的成功,或FALSE。

如果路徑不是有效目錄或目錄不能開啟,由於許可權限制或檔案系統錯誤,opendir()返回FALSE,並產生一個E_WARNING層級的PHP的錯誤。您可以抑制在opendir錯誤輸出()的前面加上'@'的函數名的前面。

報告錯誤更新日誌

版本說明
5.0.0路徑支援ftp:// URL協議。
4.3.0路徑也可以是任何網址,支援目錄列表,但是只有檔案:/ / URL協議支援在PHP 4中本

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.