Jump to content

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/68412-solved-writing-to-every-directory/
Share on other sites

"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.

<?

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...?

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.

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.

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);


?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.