-2

我希望有人可以帮助我如何将上传的文件存储在上传文件夹内的文件夹中。情况是当用户上传 3 个文件时,我希望它存储在他/她的文件夹中。让说

$directory="/upload/".$userID.";

当我消除 $userID 部分时,它工作正常。

上传过程..

/*=======================File Upload Process============================*/

            $num_files = count($_FILES['userfile']);
            $saveDirectory = "upload/".$matricNo."/";

            for($x =0; $x < $num_files; $x++)
            {
            $fileName = $_FILES['userfile']['name'][$x];
            $tempName = $_FILES['userfile']['tmp_name'][$x];
            $fileSize = $_FILES['userfile']['size'][$x];
            $fileType = $_FILES['userfile']['type'][$x];
            $allowed_ext = array ('doc','docx','pdf');
            $file_ext = pathinfo($filename, PATHINFO_EXTENSION);

                if (($_FILES['userfile']['size'][$x] > 1048576) && (in_array($file_ext, $allowed_ext) == false))
                {
                    header('location: student_newSubmission2.php?error=6');
                    exit();
                }
                elseif ($_FILES['userfile']['error'][$x] == UPLOAD_ERR_OK) 
                {
                    $query3 = oci_parse($conn,"INSERT INTO upload(uploadID, uploadname, uploadtype, uploadsize, subID) VALUES (seq_uploadID.nextval,'$fileName', '$fileType', '$fileSize',$subID)");
                    $exe3 = oci_execute($query3) or die('Error, query failed');
                    if (move_uploaded_file($tempName, $saveDirectory.$fileName)) 
                    {
                        echo 'File Successfully Uploaded!';
                    } 
                    else 
                    {
                    echo 'There was an error whilst uploading the file.';
                    }
                }           
            }   
        /*=======================File Upload End============================*/  
4

1 回答 1

4

使用mkdir(), 模式默认为 0777 , 这意味着创建动态文件夹的尽可能广泛的访问权限,

        $saveDirectory = "upload/".$matricNo."/";

        if(!is_dir($saveDirectory)){
            mkdir($saveDirectory, 0777);
        }

创建具有权限的目录:

<?php
    mkdir("/path/to/my/dir", 0700);
?>

句法:

bool mkdir ( string $pathname [, int $mode = 0777 [, bool $recursive = false [, resource $context ]]] )

pathname :目录路径。

mode:默认模式为 0777,表示最广泛的访问权限。注意模式在 Windows 上被忽略。

参考:http ://us3.php.net/mkdir

于 2013-11-15T07:06:51.860 回答