We just had severe hardware failure and need urgent help. We have a mysql database of around 500,000 "usernames". We need to use that database to re-create folders on a server, and then upload a single file into all the folders. For example: Username demo demo2 demo4 test Server Folder Path (to be created) /home/d/e/demo /home/d/e/demo2 /home/t/e/test So I need the server to automatically create all those dir's based on the username's in the database. Step two is to upload a single file into all of those directories (so the file would go into /home/d/e/demo, but not /home/d/ or /home/d/e/ .. needs to go into the account folders). Any advice?? I've been playing around with it for hours without any luck and we need it to get our free hosting operation back up after massive hardware failures. Thanks!! Any help will be GREATLY appreciated!!
Do something like... SELECT SUBSTRING(`username` FROM 1, 1) AS `first_letter`, SUBSTRING(`username` FROM 2, 1) AS `second_letter`, `username` FROM `users` Then loop through the results, use file_exists function to check if the directory & subdirectory has been made before. If not make it then fwrite a index.html file. Alternatively make an array of A to Z and loop through and make a directory & a subdirectory for each letter, you'll end up with 676 directories though. Once done this, do a scandir to get an array of the directories then do a foreach on the directory array and do an fwrite to put an index.html file in each.
<?php $host = 'localhost'; $username= 'username'; $password= 'password'; $dbname = 'dbname'; $file_to_copy = '/full/path/to/file/to/copy.php'; $folder_for_user_dirs = '/home/'; $filename = basename($file_to_copy); mysql_connect($host,$username,$password) or die('ERROR WITH DB LOGIN'); mysql_select_db($dbname) or die('DB NAME "'.$dbname.'" DOES NOT EXIST'); $query = "SELECT `username_field` FROM `user_table`"; $res = mysql_query($query); if(!$res) die('ERROR IN QUERY'); while($row = mysql_fetch_assoc($res) { $name = $row['username_field']; $folder = $folder_for_user_dirs.substr($name,0,1).'/'.substr($name,1,1).'/'; mkdir($folder.$name); copy($file_to_copy,$folder_for_user_dirs.$name.$filename); } PHP: Something like that