Jump to content

Creating a directory from selected item in dropdown menu


Recommended Posts



This is a screenshot of the script I'm trying to finish:






A simple page, with an upload box, upload button, dropdown menu with directories, text box and a Create button.


I can't see what's wrong in the code, as the folder is not getting created.


What I'm trying to do is, when the 'Create' button is clicked:

  • Get path from drop down menu
  • Get text from text box
  • Create a new folder in the selected directory (from drop down menu) with the name being the value from the textbox.

This is the code:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
   <title>FileStore - Upload Files</title>
   <link rel="stylesheet" href="./CSS/style.css" type="text/css" media="screen, projection" />
<div id="wrapper">
   <header id="header">

   <div id="header-content">
    <strong><h1>FileStore</h1></strong> Upload multiple files at once!
   <div class="login-info" >

   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">
    echo "<p align='right'>You are not logged in.</p>";
    echo "<b><a href='registration.php'>Register</a></b>";

    echo $welcomeMsg;

   </header><!-- #header-->
   <section id="middle" align="center">
    <div id="container">
	    <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 action="" method='post' >
   <select name="myDirs">
		    <option value=""  selected="selected">Select a folder</option>

global $userid;
global $up_path;
global $sPath;
$Username = $_SESSION["username"];

$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'];
$sPath = realpath("./files/" . $userid );
if (!file_exists($sPath)) {

    mkdir($folder_path, 0777, true);
    chmod($folder_path, 0777);

if (chdir($sPath)) {
$iterator = new RecursiveIteratorIterator( new RecursiveDirectoryIterator($sPath, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST);
foreach($iterator as $file) {
   if($file->isDir()) {

  echo '<option value="'.$file.'">'.$file."</option>\n";


echo var_dump($file);

echo "<form action='' method='post' name='dircreation'>";
echo "<input type='text' name='newDir' > ";	 
echo "<input type='submit' value='Create'>";
echo "</form>";
if(isset($_POST['dircreation'])) {
$selected_path = $_POST["myDirs"];
$newDir = $_POST["newDir"];

//$fPath = realpath($sPath. "/" . $file . "/");
$folder_path = $selected_path .  "/" .  $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;

} else if (isset($_POST['upload[]'])) {

 $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.";
 $vpath = strlen($userid);
 $upload_dir  = './files/' . (string)$userid . '/';
 $num_files = count($_FILES['upload']['name']);

 if (!file_exists($upload_dir)) {
  mkdir($sPath, 0777, true);
  chmod($sPath, 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><!-- #content-->
    </div><!-- #container-->
    <aside id="sideLeft">
	    <div id="menu-x" align="center"><br>
			    <div class="menu">
				    <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>
				    <br style="clear:left"/>

    </aside><!-- #sideLeft -->
   </section><!-- #middle-->
   <footer id="footer">
    <strong>FileStore:</strong> A CMT 3315 Project by Brian Livori
   </footer><!-- #footer -->
</div><!-- #wrapper -->

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.