dongyue3795 2013-11-15 07:00
浏览 43
已采纳

如何在上传文件夹中的新文件夹中上传文件?

I hope someone can help me on how can I store the file uploaded in a folder inside the upload folder.. the situation is when user upload 3 files, I want it to store in his/her folder.. let say

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

When I eliminate the $userID part, it works fine.

the upload process..

/*=======================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============================*/  
  • 写回答

1条回答 默认 最新

  • doudou130216 2013-11-15 07:06
    关注

    Use mkdir(), The mode is 0777 by default, which means the widest possible access to create dynamic folders,

            $saveDirectory = "upload/".$matricNo."/";
    
            if(!is_dir($saveDirectory)){
                mkdir($saveDirectory, 0777);
            }
    

    Create dir with permission:

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

    Syntax:

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

    pathname : The directory path.

    mode: The mode is 0777 by default, which means the widest possible access. Note: mode is ignored on Windows.

    Ref: http://us3.php.net/mkdir

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

报告相同问题?

悬赏问题

  • ¥15 FileNotFoundError 解决方案
  • ¥15 uniapp实现如下图的图表功能
  • ¥15 u-subsection如何修改相邻两个节点样式
  • ¥30 vs2010开发 WFP(windows filtering platform)
  • ¥15 服务端控制goose报文控制块的发布问题
  • ¥15 学习指导与未来导向啊
  • ¥15 求多普勒频移瞬时表达式
  • ¥15 如果要做一个老年人平板有哪些需求
  • ¥15 k8s生产配置推荐配置及部署方案
  • ¥15 matlab提取运动物体的坐标