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

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

报告相同问题?

悬赏问题

  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan