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 请问为什么我配置IPsec后PC1 ping不通 PC2,抓包出来数据包也并没有被加密
  • ¥200 求博主教我搞定neo4j简易问答系统,有偿
  • ¥15 nginx的使用与作用
  • ¥100 关于#VijeoCitect#的问题,如何解决?(标签-ar|关键词-数据类型)
  • ¥15 一个矿井排水监控系统的plc梯形图,求各程序段都是什么意思
  • ¥15 ensp路由器启动不了一直报#
  • ¥50 安卓10如何在没有root权限的情况下设置开机自动启动指定app?
  • ¥15 ats2837 spi2从机的代码
  • ¥200 wsl2 vllm qwen1.5部署问题
  • ¥100 有偿求数字经济对经贸的影响机制的一个数学模型,弄不出来已经快要碎掉了