Php 目录树迭代器";致命错误:未捕获异常';意外值异常';带有消息';递归目录迭代器::“构造”;
我遇到了上述错误的问题。似乎我从未将文件夹添加到Php 目录树迭代器";致命错误:未捕获异常';意外值异常';带有消息';递归目录迭代器::“构造”;,php,Php,我遇到了上述错误的问题。似乎我从未将文件夹添加到recursivedirectoryinterator中,我收到了此错误消息 目前,它可以很好地使用以下路径:C:\wamp642\www\\refit\code\username\u 2但是当我添加这样一个文件夹时:C:\wamp642\www\\refit\code\username\u 2\files 它抛出以下错误: Fatal error: Uncaught exception 'UnexpectedValueException' wit
recursivedirectoryinterator
中,我收到了此错误消息
目前,它可以很好地使用以下路径:C:\wamp642\www\\refit\code\username\u 2
但是当我添加这样一个文件夹时:C:\wamp642\www\\refit\code\username\u 2\files
它抛出以下错误:
Fatal error: Uncaught exception 'UnexpectedValueException' with message
'RecursiveDirectoryIterator::__construct(C:\wamp642\www\refit\code\username_2iles,C:\wamp642\www\refit\code\username_2iles):
The filename, directory name, or volume label syntax is incorrect.
(code: 123)' in C:\wamp642\www\refit\code\username_2\files\curzon_1.php on line 13
我的代码:
<?php
$mysqli = new mysqli("localhost", "admin", "asd123", "slick");
if($mysqli->connect_error)
{
exit('Error db');
}
$username = 'username_2';
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli->set_charset("utf8mb4");
$_SESSION['mysqli'] = $mysqli;
$it = new RecursiveTreeIterator(new RecursiveDirectoryIterator("C:\wamp642\www\\refit\code\username_2", RecursiveDirectoryIterator::SKIP_DOTS));
foreach($it as $path => $branch)
{
if(is_dir($path))
{
echo "".$path. "<br>";
if(!file_exists("files"))
{
mkdir("files");
}
//echo $it.'<br>';
$schism = pathinfo($path);
echo "".$schism['basename']."<br>";
$original_path = $path;
$folder_name = $schism['basename'];
if($schism['basename'] == "files")
{
echo '';
}
else
{
mkdir("files\\".$schism['basename']."");
}
}
if(is_file($path))
{
echo "".$path."<br>";
$schism = pathinfo($path);
$media = basename($path).PHP_EOL;
$stmt = $mysqli->prepare("INSERT INTO ".$username." (original_path, folder_name, media) VALUES (?, ?, ?)");
$stmt->bind_param("sss", $original_path, $folder_name, $media);
$stmt->execute();
$stmt->close();
}
}
?>
为什么不使用单引号而忘记双斜杠呢?我不知道lol。所以你的意思是:mkdir(“files\\”$schism['basename'])代码>如下:mkdir('files\'.$schism['basename'].')
我认为它与文件夹file
有关,该文件夹就是这个php文件所在的文件夹。代码使用的路径是笔直的\uuuuu DIR\uuuu
,所以我想知道是否是这样。问题是,当我试图让这个php在“files\folder”中迭代时,它不起作用。有什么想法吗?