DiscoTrio Posted November 22, 2009 Share Posted November 22, 2009 This will be a huge job and I could get it done by hand but we will need to do this many times. Currently we have a system that creates folders and copies files into them. The folders are named the same as the user accounts. I have a database with all user accounts already in place. I need help bouncing ideas on how to go bout making a file that would use those resources to re-copy the file into all those pre-existing folders so our old users don't miss out. Is this enough info? If it wont be to hard please include some coding. Im using php (of course) Quote Link to comment https://forums.phpfreaks.com/topic/182456-need-help-creating-array-to-copy-file-into-hundreds-of-folders-with-different-us/ Share on other sites More sharing options...
dbillings Posted November 22, 2009 Share Posted November 22, 2009 Not enough detail. Quote Link to comment https://forums.phpfreaks.com/topic/182456-need-help-creating-array-to-copy-file-into-hundreds-of-folders-with-different-us/#findComment-962902 Share on other sites More sharing options...
DiscoTrio Posted November 22, 2009 Author Share Posted November 22, 2009 More details: When users sign up on my site they are given a folder and a file. The file that is copied in is changed due to updates often. We now have hundreds of users and when we change the file only new users get it becuase its to painfull to update file in every folder by hand... We need a way to update all those folders automatically. (All usernames stored in database which is the same as filename) (text files are placed in all folders that have the username(filename) in it) Quote Link to comment https://forums.phpfreaks.com/topic/182456-need-help-creating-array-to-copy-file-into-hundreds-of-folders-with-different-us/#findComment-962903 Share on other sites More sharing options...
DiscoTrio Posted November 22, 2009 Author Share Posted November 22, 2009 anyone there? Quote Link to comment https://forums.phpfreaks.com/topic/182456-need-help-creating-array-to-copy-file-into-hundreds-of-folders-with-different-us/#findComment-962912 Share on other sites More sharing options...
dbillings Posted November 22, 2009 Share Posted November 22, 2009 are these read only files? Quote Link to comment https://forums.phpfreaks.com/topic/182456-need-help-creating-array-to-copy-file-into-hundreds-of-folders-with-different-us/#findComment-962914 Share on other sites More sharing options...
DiscoTrio Posted November 22, 2009 Author Share Posted November 22, 2009 nope, can be read, write, and errrr, copied, whatever. Quote Link to comment https://forums.phpfreaks.com/topic/182456-need-help-creating-array-to-copy-file-into-hundreds-of-folders-with-different-us/#findComment-962916 Share on other sites More sharing options...
dbillings Posted November 22, 2009 Share Posted November 22, 2009 I'm not sure php is the best answer for something like this, but maybe someone else has an idea. Quote Link to comment https://forums.phpfreaks.com/topic/182456-need-help-creating-array-to-copy-file-into-hundreds-of-folders-with-different-us/#findComment-962920 Share on other sites More sharing options...
DiscoTrio Posted November 22, 2009 Author Share Posted November 22, 2009 Ok, I can easily put al foldernames in a string, can we work with that? Quote Link to comment https://forums.phpfreaks.com/topic/182456-need-help-creating-array-to-copy-file-into-hundreds-of-folders-with-different-us/#findComment-962923 Share on other sites More sharing options...
dbillings Posted November 22, 2009 Share Posted November 22, 2009 You really wouldn't need to do that you can use the directory functions to read what files are in the directory. http://us3.php.net/manual/en/function.opendir.php Quote Link to comment https://forums.phpfreaks.com/topic/182456-need-help-creating-array-to-copy-file-into-hundreds-of-folders-with-different-us/#findComment-962930 Share on other sites More sharing options...
dbillings Posted November 22, 2009 Share Posted November 22, 2009 This looks promising as well. http://us2.php.net/copy Quote Link to comment https://forums.phpfreaks.com/topic/182456-need-help-creating-array-to-copy-file-into-hundreds-of-folders-with-different-us/#findComment-962933 Share on other sites More sharing options...
dbillings Posted November 22, 2009 Share Posted November 22, 2009 Something like this would probably work. This is not tested and may have errors also I don't know what you're using to grab the files from one directory multiple directories? <?php // master directory with common files desired to populate user directories $masterDir = '/somedirectory'; $masterFiles = scandir($masterDir); //assuming all user directories are subdirectories of a higher level user directory $userDir = '/userdirectory'; $userFiles = scandir($userDir); for($i=0; $i<count($userFiles); $i++) { for($x=0; $x<count($masterFiles); $x++) { copy($masterFiles[x], $userFiles[i]."/$masterFiles[x]"); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/182456-need-help-creating-array-to-copy-file-into-hundreds-of-folders-with-different-us/#findComment-962945 Share on other sites More sharing options...
dbillings Posted November 22, 2009 Share Posted November 22, 2009 ooo lookie here <?php function smartCopy($source, $dest, $folderPermission=0755,$filePermission=0644){ # source=file & dest=dir => copy file from source-dir to dest-dir # source=file & dest=file / not there yet => copy file from source-dir to dest and overwrite a file there, if present # source=dir & dest=dir => copy all content from source to dir # source=dir & dest not there yet => copy all content from source to a, yet to be created, dest-dir $result=false; if (is_file($source)) { # $source is file if(is_dir($dest)) { # $dest is folder if ($dest[strlen($dest)-1]!='/') # add '/' if necessary $__dest=$dest."/"; $__dest .= basename($source); } else { # $dest is (new) filename $__dest=$dest; } $result=copy($source, $__dest); chmod($__dest,$filePermission); } elseif(is_dir($source)) { # $source is dir if(!is_dir($dest)) { # dest-dir not there yet, create it @mkdir($dest,$folderPermission); chmod($dest,$folderPermission); } if ($source[strlen($source)-1]!='/') # add '/' if necessary $source=$source."/"; if ($dest[strlen($dest)-1]!='/') # add '/' if necessary $dest=$dest."/"; # find all elements in $source $result = true; # in case this dir is empty it would otherwise return false $dirHandle=opendir($source); while($file=readdir($dirHandle)) { # note that $file can also be a folder if($file!="." && $file!="..") { # filter starting elements and pass the rest to this function again # echo "$source$file ||| $dest$file<br />\n"; $result=smartCopy($source.$file, $dest.$file, $folderPermission, $filePermission); } } closedir($dirHandle); } else { $result=false; } return $result; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/182456-need-help-creating-array-to-copy-file-into-hundreds-of-folders-with-different-us/#findComment-962953 Share on other sites More sharing options...
emopoops Posted November 22, 2009 Share Posted November 22, 2009 if u are populating a whole bunch of directory with the same file, why dont u just use a file that the user starts with that requires the main file(that u can always change) Quote Link to comment https://forums.phpfreaks.com/topic/182456-need-help-creating-array-to-copy-file-into-hundreds-of-folders-with-different-us/#findComment-962956 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.