almightyegg Posted April 8, 2009 Share Posted April 8, 2009 I have a file that when executed it re-writes a group of files to a list of directorys like so: <? $openfile = fopen("/home/lordofth/public_html/areas/panel.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/panel.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/areas/links.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/links.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/areas/links2.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/links2.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/areas/icons.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/icons.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/areas/default.css", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/default.css")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/areas/default2.css", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/default2.css")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/areas/copyright.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/copyright.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/areas/bbcodes.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/bbcodes.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/account/panel.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/panel.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/account/links.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/links.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/account/links2.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/links2.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/account/icons.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/icons.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/account/default.css", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/default.css")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/account/default2.css", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/default2.css")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/account/copyright.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/copyright.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/account/bbcodes.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/bbcodes.php")); fclose($openfile); Problem is, there's about 20 or so directories to fwrite() 8 files into, which from the above code, makes a large and long winded file. So I was wondering, for ease of use, if it's possible to put the directories into an array of something and then it would fwrite() to all directories in there?? If it is possible, it'd be great if you could point me in the right direction, thanks Quote Link to comment Share on other sites More sharing options...
Yesideez Posted April 8, 2009 Share Posted April 8, 2009 Sure - you can create one (or more if neede) array(s) but you'd need to then write a foreach() loop to run through performing the tasks. Quote Link to comment Share on other sites More sharing options...
Yesideez Posted April 8, 2009 Share Posted April 8, 2009 Try this... <?php $source='/home/lordofth/public_html/layout/'; $target='/home/lordofth/public_html/areas/'; $arrFiles=array('panel.php','links.php','links2.php','icons.php','default.css','default2.css','copyright.css','bbcodes.php'); copyFiles($source,$target,$arrFiles); $source='/home/lordofth/public_html/layout/'; $target='/home/lordofth/public_html/account/'; $arrFiles=array('panel.php','links.php','links2.php','icons.phpdefault.css','default2.css','copyright.php','bbcodes.php'); copyFiles($source,$target,$arrFiles); function copyFiles($source,$target,$arrFiles) { foreach ($arrFiles as $file) { copy($source.$file,$target.$file); } } ?> EDIT: Improved code and swapped source and target round as I had them wrong. Quote Link to comment Share on other sites More sharing options...
almightyegg Posted April 8, 2009 Author Share Posted April 8, 2009 Sweet, works great - thanks loads Quote Link to comment 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.