Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9143047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:55:38+00:00 2026-06-17T09:55:38+00:00

I am trying to combine multiple form elements. I have 2 buttons, 1 tex

  • 0

I am trying to combine multiple form elements. I have 2 buttons, 1 tex tbox and 1 upload box and 1 drop down menu as shown below:

upload.php

So the user can select a directory where to upload, create a new one by clicking the ‘Create’ button and Upload files. However, with my current code, it does not work (files are uploaded to default directory).

This is the code:

<?php
  include("login.php");

?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

    <title>FileStore - Upload Files</title>
    <link rel="stylesheet" href="./CSS/style.css" type="text/css" media="screen, projection" />
</head>
<body>
<div id="wrapper">
    <header id="header">
    <div id="header-content">
        <strong><h1>FileStore</h1></strong> Upload multiple files at once!
    </div>
    <div class="login-info" >
<?php
    if ($isLoggedin === false) {
        echo '  <form action="" method="POST">
        Username: <input name="username" > 
        Password: <input type="password" name="password" size="8">
              <input type="submit" name="submit" value="Login">
                </form>';
        echo "<p align='right'>You are not logged in.</p>";
        echo "<b><a href='registration.php'>Register</a></b>";
    }else{  
         echo $welcomeMsg;
    }   
?>
    </div>
    </header><!-- #header-->
    <section id="middle" align="center">
        <div id="container">
        <br><br>
            <div id="content">
                <strong><h1>Upload files</h1></strong><br><br>
                <div id="upload-file" >
                <form action="" method="post" enctype="multipart/form-data">
                <input type="file" value="" name="upload[]" multiple>
                <button type="submit">Upload!</button>
                            </form>
                <select name="myDirs">
                <option value=""  selected="selected">Select a folder</option>
                <?php
                if (chdir("./files/" . $userid)) {
                   $dirs = glob('*', GLOB_ONLYDIR);
                   foreach($dirs as $val){
                      echo '<option value="'.$val.'">'.$val."</option>\n";
                   }        
                    } else {
                   echo 'Changing directory failed.';
                }
                ?>          
<?php
            include("dbConfig.php");
    $Username = $_SESSION["username"];
    global $userid;
    $sql = "SELECT UserID FROM users WHERE Username = '".$Username."'";
    $result = mysql_query($sql) or die(mysql_error());

    while($row = mysql_fetch_assoc($result)) {
       $userid = $row['UserID'];
    }

    $newDir = $_REQUEST["newDir"];
    $upload_dir  = './files/' . (string)$userid . '/';
    $folder_path = $upload_dir . "/" . $newDir . "/" ;
    if (!file_exists($folder_path)) {
            mkdir($folder_path, 0777, true);
            chmod($folder_path, 0777);  
            echo "Folder" . $newDir . "created.";
            echo "Redirecting to upload page..";
            header( 'Location: ../upload.php' ) ;
        } else {
           echo "Error creating " . $newDir;
        }   
        echo "<form action='' method='post'>";
        echo "<input type='text' name='newDir'> ";      
        echo "<input type='submit' value='Create'>";
        echo "</form>";     
?>      
<?php
        include("dbConfig.php");
        $Username = $_SESSION["username"];
        global $userid;
        global $up_path;

        $error_message[0] = "Unknown problem with upload.";
        $error_message[1] = "Uploaded file too large (load_max_filesize).";
        $error_message[2] = "Uploaded file too large (MAX_FILE_SIZE).";
        $error_message[3] = "File was only partially uploaded.";
        $error_message[4] = "Choose a file to upload.";

        $sql = "SELECT UserID FROM users WHERE Username = '".$Username."'";

        $result = mysql_query($sql) or die(mysql_error());
        while($row = mysql_fetch_assoc($result)) {
           $userid = $row['UserID'];
        }
        $vpath = strlen($userid);
        $upload_dir  = './files/' . (string)$userid . '/';
        $num_files = count($_FILES['upload']['name']);

        if (!file_exists($upload_dir)) {
            mkdir($upload_dir, 0777, true);
            chmod($upload_dir, 0777);

        } else {

            for ($i=0; $i < $num_files; $i++) {
            $upload_file = $upload_dir . urlencode(basename($_FILES['upload']['name'][$i]));

                if (@is_uploaded_file($_FILES['upload']['tmp_name'][$i])) {
                    if (@move_uploaded_file($_FILES['upload']['tmp_name'][$i], 
                        $upload_file)) {
                        /* Great success... */



                        echo basename($upload_file) . " has been uploaded. <br>";
                        //$content = file_get_contents($upload_file);
                        //echo $content;
                    } else {
                        print $error_message[$_FILES['upload']['error'][$i]];
                    }
                } else {
                    print $error_message[$_FILES['upload']['error'][$i]];
                }    
            }
        }           
?>  
        </div>                              
            </div><!-- #content-->
        </div><!-- #container-->

        <aside id="sideLeft">

            <div id="menu-x" align="center"><br>
            <strong>Menu</strong><br><br>

                    <div class="menu">
                        <ul>
                        <li><a href="index.php">Home</a></li>
                        <li><a href="upload.php">Upload</a></li>
                        <li><a href="files.php">Files</a></li>
                        <li><a href="about.php">About</a></li>
                        <li><a href="help.php">Help</a></li>
                        <li><a href="#">Logout</a></li>
                        </ul>
                        <br style="clear:left"/>
                    </div>

            </div>


        </aside><!-- #sideLeft -->

    </section><!-- #middle-->

    <footer id="footer">
        <strong>FileStore:</strong> A CMT 3315 Project by Brian Livori
    </footer><!-- #footer -->

</div><!-- #wrapper -->

</body>
</html>

I wan to enable the user to create a directory before uploading, and then choose a directory to upload by selecting an option from the drop down.

How can I do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:55:39+00:00Added an answer on June 17, 2026 at 9:55 am

    Your form tag ends before select box so move it below select box and you should get your post values related to chosen upload dir.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this code that submits multiple files and titles im trying to combine
I'm trying to combine multiple, smaller XML files into one large XML. I have
I'm trying to combine multiple column values into 1 and then label them distinctly
I'm trying to combine multiple files in multiple input directories into a single file,
So I have been trying to combine the answers of these two questions: C#
I'm trying to combine multiple JSON objects into a single one in PHP. I'm
Below is my Query in which im trying to combine multiple column values SELECT
Trying to use the following scripts to upload, resize & save multiple images via
I am trying to combine multiple commands into a single output. #!/bin/bash x=$(date +%Y)
Trying to combine an if statement using <xsl:if test=expression> where I want to have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.