php如何将文件移动到使用userid创建的文件夹(上传文件)


php-how to move files to the folder created using userid (upload files)

上传后,我将根据唯一的应用程序id创建文件夹。

我在这里面临的问题是,一旦我上传,文件就会被上传到受尊重的文件夹之外。

甚至文件夹也在创建中。

谁能帮上忙吗!!!

$path = $file['name'];
$path_user = '/home/devestctrl/public_html/wp-content/plugins/est_collaboration/Files/'.'/'.$send_id;
if (!file_exists($path_user)) {
    if (mkdir( $path_user,0766,false )) {
        if (move_uploaded_file($file['tmp_name'],$path_user.$path)) {
            echo"inside 2"."<br>";
            echo"Your File Successfully Uploaded";
        }                 
    }
}

删除est_collaboration/Files/'.$send_id之间多余的/

最后追加/。像

$path_user = '/home/devestctrl/public_html/wp-content/plugins/est_collaboration/Files/'.$send_id.'/';

您需要在$path_user$path:之间添加斜线

$path_user = '/home/devestctrl/public_html/wp-content/plugins/est_collaboration/Files/'.'/'.$send_id;
if (!is_dir($path_user)) {
    if (!mkdir($path_user, 0766, false)) {
        die('Directory cannot be created'); // handle this exception
    }
}
if (move_uploaded_file($file['tmp_name'], $path_user . '/' . $path)) {
// ----- You are missing this slash -------------------^^^------------
    echo "inside 2"."<br>";
    echo "Your File Successfully Uploaded";
}