目录树迭代器“致命错误:未捕获的异常'UnexpectedValueException',消息'RecursiveDirectoryIterator :: __ construct”

时间:2018-06-12 14:36:14

标签: php

我遇到上述错误。似乎每当我向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();
    }

}

?>

谢谢你的到来。

0 个答案:

没有答案