使用随机函数创建目录时出错


error in creating directory using random function

我试图创建一个随机目录保存上传的照片使用下面的代码,但它不工作。有人能帮忙吗?

//Photo upload script
if(isset($_FILES['profilepic']))
{
    if(((@$_FILES["profilepic"]["type"]=="image/jpeg")||(@$_FILES["profilepic"]["type"]=="image/png")||(@$_FILES["profilepic"]["type"]=="image/gif")) && (@$_FILES["profilepic"]["size"]<2048576))
    {
        $chars = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM123456789";
        $rand_dir_name=substr(str_shuffle($chars),0,15);
        mkdir("./userdata/images/$rand_dir_name");
        //mkdir("''userdata''images''".$rand_dir_name,077,true); //tried this but no luck
        if(file_exists("userdata/images/$rand_dir_name/".@$_FILES["profilepic"]["name"]))
        {
            echo @$_FILES["profilepic"]["name"]."Already exists";
        }
        else
        {
            move_uploaded_file(@$_FILES["profilepic"]["temp_name"],"userdata/images/$rand_dir_name/".$_FILES[profilepic][name]);
            echo "Uploaded and Stored in userdata/images/$rand_dir_name/".@$_FILES["profilepic"]["name"];
        }
    }
    else
    {
        echo "error";
    }
}

mkdir("./userdata/images/$rand_dir_name");

这一行应该是:

mkdir("../userdata/images/$rand_dir_name"); //in this format if you are using one directory back to the relative path

mkdir("/userdata/images/$rand_dir_name"); //in this format if you are trying to create from projects root path

mkdir("userdata/images/$rand_dir_name"); //in this format if you are trying to create a directory from the relative path

不能有单点(.)后跟正斜杠