Print

Printed September 8, 2010 from B&T's Tips & Scripts
http://tips-scripts.com


Copying the php.ini file

You can find another Tip on this page for how to create a custom php.ini file.  But after you create it, many hosts will require you to put a copy in each directory.  This script makes it easy.  It will copy the php.ini file from your main public directory and put one in all the subdirectories.  If you do not want it in every subdirectory, after you delete the ones you do not want you can do all future updates with the overwriteOnly flag on.

You can download this script as a .txt file.  Remember to rename the file as a .php file.

- - Start Script Here - -
<?php
// set this value to Y if you only want to overwrite old php.ini files
// set this value to N if you want to put a php.ini file in every directory
$overwriteOnly "Y";
// full path to the location of your home directory where the php.ini file is located that you want to copy to lower lever directories
$path "/home/" get_current_user() . "/public_html";
// change nothing below this line
if ($overwriteOnly == "Y") echo "Operating in Overwrite Only Mode<br><br>";
$source $path "/php.ini";
if (!
file_exists($source)) die('Error - no source php.ini file');
function 
search($dir) {
  global 
$source$overwriteOnly;
  foreach(
scandir($dir) as $filename) {
    if (
$filename !== '.' AND $filename !== '..' AND $filename !== 'cgi-bin' AND is_dir("$dir/$filename") ) {
      
$path $dir."/".$filename
      
$target $path "/php.ini";
      if (!
file_exists($target) AND $overwriteOnly == "Y") {
        echo 
"$path <b>skipped - no php.ini file</b><br>";
      } else {
        echo 
"$target <br>";
        if (!
copy($source,$target)) echo "<b>Write failed for $target </b><br>";
        if (
file_exists($target)) chmod($target,0600);
    }
      
search($path);
    }
  }
}
search($path);
echo 
"<br>Done.";
?>

- - End Script Here - -