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 8196605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:32:13+00:00 2026-06-07T05:32:13+00:00

if(!empty($_POST[‘newdir’])) { $dir_base= preg_replace(/[^a-zA-ZÀ-ÿ0-9\s]/,”,$_POST[‘newdir’]); $dir_path=$pattern.$dir_base; $dir_path_lwr = strtolower($dir_path); $old_dirs = glob($pattern.’*’, GLOB_ONLYDIR); $old_dirs_lwr =

  • 0
if(!empty($_POST['newdir'])) {
    $dir_base= preg_replace("/[^a-zA-ZÀ-ÿ0-9\s]/",'',$_POST['newdir']);
    $dir_path=$pattern.$dir_base;
    $dir_path_lwr = strtolower($dir_path);

    $old_dirs = glob($pattern.'*', GLOB_ONLYDIR);
    $old_dirs_lwr = array_map('strtolower', $old_dirs);

    $i = 1;
    $cond = true;
    while($cond) {

        if(in_array($dir_path_lwr, $old_dirs_lwr)) {
            $i++;
            $new_base=$dir_base.' '.$i.'';
            $new_path= $pattern.$new_base;
            $dir_path_lwr = strtolower($new_path);
        }
        elseif(!in_array($dir_path_lwr, $old_dirs_lwr)) {
            mkdir($dir_path, 0755);
            $cond = false;
        }
    }
}

EDIT Have changed the above to the most recent version. For testing, I am now simply echoing out the $cond var rather than creating directories all over the place. The ‘Not In’ argument works fine – when a duplicate name IS found, the page takes about 10 to 12 seconds to load, before white screening. There’s something wrong with my while loop i think…

What I’m trying to do is:

  • Submit a new directory name to the script
  • Clean and escape that name
  • Check it against existing directories in that location ($pattern)
  • If there is no conflict, create the directory (works)
  • If there is a conflict, append a number (eg, My Directory 2) and then create the directory (doesn’t work)

So, basically how to check against existing file names, and create a uniquely name directory dynamically. All help appreciated 🙂

  • 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-07T05:32:14+00:00Added an answer on June 7, 2026 at 5:32 am

    Fixed it – i was confusing the vars within the loop.

    Posting for future reference:

    if(!empty($_POST['newdir'])) {
        $dir_base= preg_replace("/[^a-zA-ZÀ-ÿ0-9\s]/",'',$_POST['newdir']);
        $dir_path=$pattern.$dir_base;
        $dir_path_lwr = strtolower($dir_path);
    
        $old_dirs = glob($pattern.'*', GLOB_ONLYDIR);
        $old_dirs_lwr = array_map('strtolower', $old_dirs);
    
        $i = 1;
        $cond = true;
        while($cond) {
    
            if(in_array($dir_path_lwr, $old_dirs_lwr)) {
                $i++;
                $new_base=$dir_base.' '.$i.'';
                $dir_path= $pattern.$new_base;
                $dir_path_lwr = strtolower($dir_path);
            }
            elseif(!in_array($dir_path_lwr, $old_dirs_lwr)) {
                mkdir($dir_path, 0755);
                $cond = false;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use if(!empty($_POST['login'])){ } for checking that login is file is filled, it work
I have the following code validation php script: if(empty($_POST['captcha_code'])) { $error = 1; $code[3]
this is my entire PHP code: <?php if(empty($_POST['selid'])) {echo no value selected; } else
Right now i have this for full name: if(empty($_POST['full_name']) || strlen($_POST['full_name']) < 4) {
Here is my code: if (isset($_POST['addmonths'])){ if (!empty($_POST['months'])){ if (is_numeric($_POST['months'])){ $monthtoadd = $_POST['months']; if
Here is my code: if (isset($_POST['addmonths'])){ if (!empty($_POST['months'])){ if (is_numeric($_POST['months'])){ $monthstoadd = $_POST['months']; if
Here is my code: if(isset($_POST['check']) AND $_POST['check'] == 'First') { $errormessage = array(); if(empty($_POST['full_name'])
Consider the following if(!count($_POST)) { echo 'something'; } if(empty($_POST)) { echo 'something'; } if(!$_POST)
I saw the following code snippet: <?php if(!empty($_POST)): // case I: what is the
I tried using: // do login if request is posted if (isset($_POST) && !empty($_POST))

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.