我正在编写一个文件散列类,但一开始就卡住了。
class fileHashing
{
private $start_path = '../../../test';
private $log_path = '../../../test/log';
private $log_file = 'fileHash.xyz';
function __construct()
{
$this->open();
}
private function open() {
$files_list = scandir($this->start_path);
print_r($files_list);
date_default_timezone_set('Europe/Rome');
foreach ($files_list as $key => $element) {
if (is_file($element)) {
echo "FILE: " . $element . PHP_EOL;
} elseif (is_dir($element)) {
echo "DIR: " . $element . PHP_EOL;
} else {
echo "NONE: " . $element . PHP_EOL;
}
}
}
}
$a = new fileHashing();
返回:
Array
(
[0] => .
[1] => ..
[2] => fileupload.php
[3] => log
[4] => test1.php
[5] => tsconfig.json
)
DIR: .
DIR: ..
FILE: fileupload.php
NONE: log
NONE: test1.php
NONE: tsconfig.json
log
是一个文件夹,它不承认它,都test1.php
和tsconfig.json
不确认文件。我错过了什么scandir()
/ is_file()
/is_dir()
吗?
您还应该将 附加start_path
到您的文件名中is_file
和is_dir
。可以这样做
private function open() {
$files_list = scandir($this->start_path);
print_r($files_list);
date_default_timezone_set('Europe/Rome');
foreach ($files_list as $key => $element) {
$file = $this->start_path . '/' . $element;
if (is_file($file)) {
echo "FILE: " . $element . PHP_EOL;
} elseif (is_dir($file)) {
echo "DIR: " . $element . PHP_EOL;
} else {
echo "NONE: " . $element . PHP_EOL;
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句