我遇到上述错误。似乎每当我向RecursiveDirectoryIterator
添加文件夹时,我都会收到此错误消息。
目前它可以正常使用此路径:C:\wamp642\www\\refit\code\username_2
但是当我添加如下文件夹时:C:\wamp642\www\\refit\code\username_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();
}
}
?>
谢谢你的到来。