Jump to content

mkdir() help


Smackie

Recommended Posts

Greetings,

 

        I'm alittle new to mkdir lol.. here is what im wanting to do.

 

When a user signs up for my site (after the fill in the fields and press submit) it will send them to a new page. which will send there data to database. how can i make it where it will create a new sub folder in say users sub folder..?

 

Sorry if i confused ya there.

 

basically when a user signs up it will create a sub folder (named  Smackie)

it will put it in users so say it would be www/users/Smackie or however the path is..

how can i do this?

 

 

Thank you

Smackie

 

Link to comment
Share on other sites

<?php
$create_folder = 'someusername';  //this is the name of the folder you want to create

    $dir =  '../'; //define your USERS directory, relative to the script that is running's location
    if(!$dh = opendir($dir))
    {
      echo('Failed to open directory: ' . $dir . );
    }//open dir
    
    //read folders/(i think this would pick up files as well)that already exist from the directory
   //place into an array to search
    $fileList = array();
    while (false !== ($file = readdir($dh))) {
        if ($file != "." && $file != "..") {
            $fileList[] = $file;
        }
    }//while
    closedir($dh);

    //check that there are no matching folder names
    if(in_array($create_folder,$fileList))
    {
      echo('Directory ' . $create_folder . ' already exists.');
    }else{
       // REMEMBER TO have MKDIR's path relative to the scripts location or else it will make it in the same folder as the running script!
      if(!mkdir("../$create_folder", 0700))
      {
        echo('Failed to create directory.');
      }
?>

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.

Guest
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.