日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php读取子目录下文件内容,php小代码----目录下读取子文件或子目录_PHP教程

發布時間:2023/12/9 php 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php读取子目录下文件内容,php小代码----目录下读取子文件或子目录_PHP教程 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

php小代碼----目錄下讀取子文件或子目錄

rootPath = $rootPath;

if (is_dir($this->rootPath)) {

$this->rootPath = pathinfo($this->rootPath, PATHINFO_DIRNAME) . DIRECTORY_SEPARATOR . pathinfo($this->rootPath, PATHINFO_BASENAME);

$this->opDirectory = dir($this->rootPath);

} else {

$this->errorMsg = '您提供的目錄不存在!';

$this->errorNo = 1001;

throw new Exception($this->errorMsg, $this->errorNo);

}

}

private function read($directory, $parentPath, $modeInfo = 'mixed', $defaultDir = false, $fullPath = false) {

$dirInfo = array();

while (FALSE !== ($childDirOrFileName = $directory->read())) {

switch ($modeInfo) {

case self::RECDIR_MIXED:

if ($defaultDir) {

$dirInfo[] = $fullPath ? $parentPath . DIRECTORY_SEPARATOR . $childDirOrFileName : $childDirOrFileName;

} else {

if ($childDirOrFileName != '.' && $childDirOrFileName != '..') {

$dirInfo[] = $fullPath ? $parentPath . DIRECTORY_SEPARATOR . $childDirOrFileName : $childDirOrFileName;

}

}

break;

case self::RECDIR_DIR:

if (is_dir($parentPath . DIRECTORY_SEPARATOR . $childDirOrFileName)) {

if ($defaultDir) {

$dirInfo[] = $fullPath ? $parentPath . DIRECTORY_SEPARATOR . $childDirOrFileName : $childDirOrFileName;

} else {

if ($childDirOrFileName != '.' && $childDirOrFileName != '..') {

$dirInfo[] = $fullPath ? $parentPath . DIRECTORY_SEPARATOR . $childDirOrFileName : $childDirOrFileName;

}

}

}

break;

case self::RECDIR_FILE:

if (is_file($parentPath . DIRECTORY_SEPARATOR . $childDirOrFileName)) {

$dirInfo[] = $fullPath ? $parentPath . DIRECTORY_SEPARATOR . $childDirOrFileName : $childDirOrFileName;

}

break;

}

}

return $dirInfo;

}

/**

* (PHP 5 >= 5.4.0)

* 得到目錄下的直接子目錄或直接子文件信息

* @param string $modeInfo[可選]

* 返回目錄下信息的模式

* mixed 返回所有的文件名及目錄名

* dir 返回所有的目錄名

* file 返回所有的文件名

*

* @param bool $defaultDir[可選]

* 是否包括默認的鏈接目錄..和.

* false 不包括

* true 包括

*

* @param bool $fullPath[可選]

* 是否返回子文件或目錄的路徑信息

* true 是

* false 否

*

* @return array 返回一個數組,記錄了該目錄下的信息

*/

public function getPathDirectDirInfo($modeInfo = 'mixed', $defaultDir = false, $fullPath = false) {

return $this->read($this->opDirectory, $this->rootPath, $modeInfo, $defaultDir, $fullPath);

}

}

//----------------------------test-----------------------------------------

header("Content-type:text/html; charset=UTF-8");

try {

$recDir = new RecDir('./CALLTEMP/');

$dirs = $recDir->getPathDirectDirInfo('file', true, true);

var_dump($dirs);

} catch (Exception $ex) {

echo '在文件【' . $ex->getFile() . '】中的第' . $ex->getLine() . '行報錯:' . $ex->getMessage() . '(' . $ex->getCode() . ')';

}

http://www.bkjia.com/PHPjc/1053347.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1053347.htmlTechArticlephp小代碼----目錄下讀取子文件或子目錄 ?php class RecDir { protected $rootPath; protected $opDirectory; const RECDIR_MIXED = mixed; const RECDIR_DIR = dir; const RECD...

本條技術文章來源于互聯網,如果無意侵犯您的權益請點擊此處反饋版權投訴

本文系統來源:php中文網

總結

以上是生活随笔為你收集整理的php读取子目录下文件内容,php小代码----目录下读取子文件或子目录_PHP教程的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。