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
https://forums.phpfreaks.com/topic/109778-mkdir-help/
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
https://forums.phpfreaks.com/topic/109778-mkdir-help/#findComment-563731
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.