PHP Directory 函數的詳解_PHP教程

來源:互聯網
上載者:User
預定義常量:

DIRECTORY_SEPARATOR (string) :目錄分隔字元

PATH_SEPARATOR (string) :路徑分隔字元


bool chdir ( string $directory )— 改變目錄

複製代碼 代碼如下:

echo getcwd() . "\n";
chdir('public_html');
echo getcwd() . "\n";

bool chroot ( string $directory )— 改變根目錄,僅在系統支援且運行於 CLI,CGI 或嵌入 SAPI 版本時才行。

dir::dir ( string $directory )— directory 類,有三個方法可用:read,rewind(將檔案內部的位置指標重新指向一個資料流開頭) 和 close

複製代碼 代碼如下:
$d = dir("E:/work/html");
foreach($d as $k=>$v){
echo $k.'->' .$v. '
';
}
while(false !== ($entry = $d->read())){
echo $entry."
";
}
$d->close();

void closedir ( resource $dir_handle )— 關閉目錄控制代碼

複製代碼 代碼如下:
$dir = "/etc/php5/";

if (is_dir($dir)) {
if ($dh = opendir($dir)){
$directory = readdir($dh);
closedir($dh);
}
}

string getcwd ( void )— 取得當前工作目錄

resource opendir ( string $path [, resource $context ] )— 開啟目錄控制代碼

string readdir ( resource $dir_handle )— 從目錄控制代碼中讀取條目

複製代碼 代碼如下:
if ($handle = opendir('/path/to/files')) {
echo "Directory handle: $handle\n";
echo "Files:\n";
while (false !== ($file = readdir($handle))) {
echo "$file\n";
}
closedir($handle);
}

void rewinddir ( resource $dir_handle ) —將 dir_handle 指定的目錄流重設到目錄的開頭

array scandir ( string $directory [, int $sorting_order [, resource $context ]] )— 列出指定路徑中的檔案和目錄

複製代碼 代碼如下:
$dir = '/tmp';
$files1 = scandir($dir);
$files2 = scandir($dir, 1);
print_r($files1);
print_r($files2);

http://www.bkjia.com/PHPjc/326745.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/326745.htmlTechArticle預定義常量: DIRECTORY_SEPARATOR (string) :目錄分隔字元 PATH_SEPARATOR (string) :路徑分隔字元 bool chdir ( string $directory )— 改變目錄 複製代碼 代碼如下...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.