douwa6220 2015-08-30 16:47
浏览 72
已采纳

mkdir()不使用此代码为上传照片创建随机目录名称

// profile picture upload
if (isset($_FILES['profilepic'])) {
    if ( ((@$_FILES["profilepic"]["type"]=="image/jpeg")
            || (@$_FILES["profilepic"]["type"]=="image/png")
            || (@$_FILES["profilepic"]["type"]=="image/gif"))
        && (@$_FILES["profilepic"]["size"] < 1048576) ) //1 Megabyte
    {
        $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        $rand_dir_name = substr(str_shuffle($chars), 0, 15);

        mkdir("userdata/profile_pics/$rand_dir_name");

This is the directory all my files are: C:/xampp/htdocs/asweb

And this is where I want to keep the new directory: C:/xampp/htdocs/asweb/userdata/profile_pics

  • 写回答

1条回答 默认 最新

  • duancong7358 2015-08-30 17:04
    关注

    I just tested the following:

    $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    $rand_dir_name = substr(str_shuffle($chars), 0, 15);
    echo $rand_dir_name.$b;    // ojTxNHb0RuiyKze
    
    mkdir("c:\\dev\\".$rand_dir_name,0777,TRUE);
    

    It made c:\dev\ojTxNHb0RuiyKze no problem. I went in there and saved a text file.

    The Manual page says

    mode

    The mode is 0777 by default, which means the widest possible access. For more information on modes, read the details on the chmod() page.

    Note: mode is ignored on Windows. Note that you probably want to specify the mode as an octal number, which means it should have a leading zero. The mode is also modified by the current umask, which you can change using umask().

    However on linux, have it follow chmod values.

    Edit: op can't do it, here we go again:

    $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    $rand_dir_name = substr(str_shuffle($chars), 0, 15);
    echo $rand_dir_name.$b;    // l1TGXW3kgQcr2N5
    mkdir("C:\\xampp\\htdocs\\asweb\\userdata\\profile_pics\\".$rand_dir_name,0777,TRUE);   
    

    made C:\xampp\htdocs\asweb\userdata\profile_pics\l1TGXW3kgQcr2N5 no problem

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?