almightyegg Posted September 7, 2007 Share Posted September 7, 2007 At least one page in every directory in my site has 4 external files which are included... Which means every time I edit one of them I have to go through all my directories to upload the new versoins usually taking me about 20 minutes...which is a lot of time where I could be coding other stuff... so here it is, is there any way I could write a script and when I run it, it will upload all 4 files to all directories? Quote Link to comment https://forums.phpfreaks.com/topic/68412-solved-writing-to-every-directory/ Share on other sites More sharing options...
lemmin Posted September 7, 2007 Share Posted September 7, 2007 doDir(glob("directory/*")); function doDir($files) { foreach($files as $folder) { if (is_dir($folder)) //upload to $folder } } You could recursively call it if you wanted it to go through subdirectories. Quote Link to comment https://forums.phpfreaks.com/topic/68412-solved-writing-to-every-directory/#findComment-343955 Share on other sites More sharing options...
almightyegg Posted September 7, 2007 Author Share Posted September 7, 2007 sorry I'm a newb, how would I put my file into the $files? through an array?? or some other way?? and does the directory/* mean it will seach all the directories itself or do I have to put something else there? Quote Link to comment https://forums.phpfreaks.com/topic/68412-solved-writing-to-every-directory/#findComment-343963 Share on other sites More sharing options...
lemmin Posted September 7, 2007 Share Posted September 7, 2007 "directory" is the name of the directory you want to "start" in. If the php file is already in that location, you just need the "*" for glob(). $files is a dynamic variable that contains all the files in the directory, including folders. All you have to do is put code for uploading the files you want where the commented line is. For Example: $openfile = fopen($folder . "/filename1toreplace.php", "w"); fwrite($openfile, file_get_contents("filenam1replacement.php"); fclose($openfile); You will need four of those for each file you are replacing. Quote Link to comment https://forums.phpfreaks.com/topic/68412-solved-writing-to-every-directory/#findComment-343974 Share on other sites More sharing options...
almightyegg Posted September 7, 2007 Author Share Posted September 7, 2007 <? function doDir($files) { foreach($files as $folder) { if (is_dir($folder)) $openfile = fopen($folder . "/panel.php", "w"); fwrite($openfile, file_get_contents("\layout\panel.php")); fclose($openfile); } } doDir(glob("account/*")); ?> It didn't upload anywhere, not even to account...? Quote Link to comment https://forums.phpfreaks.com/topic/68412-solved-writing-to-every-directory/#findComment-343988 Share on other sites More sharing options...
lemmin Posted September 7, 2007 Share Posted September 7, 2007 It shouldn't ever do anything to the base directory name that you give it. Are there any folders in the folder "account/"? The file with that code should relatively link to the directory that is the super-directory of all the directories that contain your files that you want to replace. Quote Link to comment https://forums.phpfreaks.com/topic/68412-solved-writing-to-every-directory/#findComment-343992 Share on other sites More sharing options...
almightyegg Posted September 7, 2007 Author Share Posted September 7, 2007 no, all but one of the files I want to edit are base directories.... Quote Link to comment https://forums.phpfreaks.com/topic/68412-solved-writing-to-every-directory/#findComment-343995 Share on other sites More sharing options...
lemmin Posted September 7, 2007 Share Posted September 7, 2007 This would be easier if you could roughly explain the filesystem. The code I posted was based on the assumption that the folders were all sub-directories of one directory. If they aren't you might as well just hard-code the locations in. Then you wouldn't need the function at all, just something like: $openfile = fopen(harddir/panel.php", "w"); fwrite($openfile, file_get_contents("\layout\panel.php")); fclose($openfile); And do it four times for each location. Quote Link to comment https://forums.phpfreaks.com/topic/68412-solved-writing-to-every-directory/#findComment-343998 Share on other sites More sharing options...
almightyegg Posted September 7, 2007 Author Share Posted September 7, 2007 well they are all directories like www.site.com/directoryhere could I put all the directories into and array and then somehow make it run the function on the array? Quote Link to comment https://forums.phpfreaks.com/topic/68412-solved-writing-to-every-directory/#findComment-343999 Share on other sites More sharing options...
almightyegg Posted September 8, 2007 Author Share Posted September 8, 2007 could I do this using an array??? Quote Link to comment https://forums.phpfreaks.com/topic/68412-solved-writing-to-every-directory/#findComment-344221 Share on other sites More sharing options...
almightyegg Posted September 8, 2007 Author Share Posted September 8, 2007 Warning: fopen(/home/lordofth/public_html/account/panel.php) [function.fopen]: failed to open stream: Permission denied in /home/lordofth/public_html/layout/hmmm.php on line 2 I went with hard coding it....but that came up... <? $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/arena/panel.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/panel.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/arena/links.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/links.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/arena/links2.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/links2.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/arena/icons.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/icons.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/battle/panel.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/panel.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/battle/links.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/links.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/battle/links2.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/links2.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/battle/icons.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/icons.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/forum/panel.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/panel.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/forum/links.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/links.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/forum/links2.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/links2.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/forum/icons.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/icons.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/hall/panel.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/panel.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/hall/links.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/links.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/hall/links2.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/links2.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/hall/icons.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/icons.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/im/panel.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/panel.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/im/links.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/links.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/im/links2.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/links2.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/im/icons.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/icons.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/jail/panel.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/panel.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/jail/links.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/links.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/jail/links2.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/links2.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/jail/icons.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/icons.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/market/panel.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/panel.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/market/links.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/links.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/market/links2.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/links2.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/market/icons.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/icons.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/player/panel.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/panel.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/player/links.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/links.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/player/links2.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/links2.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/player/icons.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/icons.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/quests/panel.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/panel.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/quests/links.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/links.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/quests/links2.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/links2.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/quests/icons.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/icons.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/society/panel.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/panel.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/society/links.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/links.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/society/links2.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/links2.php")); fclose($openfile); $openfile = fopen("/home/lordofth/public_html/society/icons.php", "w"); fwrite($openfile, file_get_contents("/home/lordofth/public_html/layout/icons.php")); fclose($openfile); ?> Quote Link to comment https://forums.phpfreaks.com/topic/68412-solved-writing-to-every-directory/#findComment-344224 Share on other sites More sharing options...
almightyegg Posted September 8, 2007 Author Share Posted September 8, 2007 ahh it's Chmod settings...is there a way I can set them to 777 in the fwrite when I re write them?? Quote Link to comment https://forums.phpfreaks.com/topic/68412-solved-writing-to-every-directory/#findComment-344229 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.