Creating folders with php loop

thebest8
thebest8 used Ask the Experts™
on
Hello Experts,
I have the following code:

<?php

for($counter = 1; $counter <= 50; $counter++)

	
			print "AJ00" . "$counter" . "<br>";
		
	
?>

Open in new window


This code will print AJ001. AJ002, AJ003 until AJ0050,

How can I create a folder for each reference, a folder named : AJ001, another folder named AJ002 until I reach the last folder AJ0050...

Thank you
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
NorieAnalyst Assistant

Commented:
Where do you want to create the folder(s)?
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
This should do what you want (mkdir())
<?php
define('FOLDER_PATH','YOUR PATH HERE');
for($counter = 1; $counter <= 50; $counter++) {
  $path = FOLDER_PATH . "AJ00{$counter}";
  echo "Creating {$path} ...";
  if (mkdir($path)) {
    echo "Success<br>";
  }
  else {
    echo "Failed<br>";
  }
}

Open in new window

Author

Commented:
Awsome, thanks alot
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
You are welcome.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial