Jump to content

deprecated code - need help


mihomes

Recommended Posts

Someone wrote this script for me ages ago - works fine on php4, but having some issues with php5 and the installation & reflect changes files...

 

In a nutshell it takes a file called state.txt (all 50 states one per line) and creates a directory for each.  There is then a text file for each state, for instance Alabama.txt, which has all the cities of that state.  You end up with a directory for each state with directories of each city within them.  Header and footer files as well as an index.php are used for each level.  Trying to use this it creates the directores for each state, but does so in the root folder rather than the actual location of the file on the particular site.  I realize $_SERVER['PATH_TRANSLATED'] has been removed, but replacing this with $_SERVER['SCRIPT_FILENAME'] doesn't seem to correct the issue.

 

install.php

 

<?php
   set_time_limit(0) ;

   $arr = explode("/",$_SERVER['PATH_TRANSLATED']);
   $ct = count($arr);
   unset($arr[$ct-1]);
   $path=implode("/",$arr);
   $path=$path."/";
   
   if(is_file($path."state.txt"))
    { 
        
	$lines = file($path."state.txt");
        		
      if($lines)
		{
		foreach($lines as $line) 
		  {
			if($line)
			  {
				 $state = trim($line);
				 if(!is_dir($state)) 
				  {
				    @mkdir($state,0777);
				    if(is_file($path."copieble/state/index.php"))
				       { 
						  $from = $path."copieble/state/index.php";
						  $to = $path.$state."/index.php";
				          @copy($from,$to);
						  
		               }
				  }
              }
          }
		} 
}

     @chdir($path);
           $handle=opendir('.');
		       while (($file = readdir($handle))!==false) 
				   {
                         @chdir($path);
		             if (($file != ".") && ($file != ".."))
						 { 
		                   if(is_dir($file) && $file != "copieble" && $file !="_vti_cnf")
							   {
                                   if(is_file($path.$file.".txt"))
								 { 
                                     $lines = file($path.$file.".txt");
        						           if($lines)
											{
											foreach($lines as $line) 
											  {
												if($line)
												  {
													 $city = trim($line);
													 @chdir($path.$file);
													 if(!is_dir($city)) 
                                    					{
                                                                             
															@mkdir($city,0777);
														if(is_file($path."copieble/city/index.php"))
														   { 
															 $from = $path."copieble/city/index.php";
															 $to = $path.$file."/".$city."/index.php";
															 @copy($from,$to);
															  
														   } 
													}

												  }
											  }
											} 
								 }

                                  }
		                  
		                }
		          }
		         closedir($handle); 
include("reflect_changes.php");
?>

 

reflect_changes.php

 

<?php
	$arr = explode("/",$_SERVER['PATH_TRANSLATED']);
	$ct = count($arr);
	unset($arr[$ct-1]);
	$path=implode("/",$arr);
	$filepath=$path."/copieble/state/index.php"; 
        
	//print_r($_SERVER);

// Copy here the index file for all the states folder

   if(is_file($filepath))
     {
	      chdir($path); 
		  //echo "<br>".$path."/state";
	      $handle=opendir('.');
                   
		       while (($file = readdir($handle))!==false) 
				   { 
                         if (($file != ".") && ($file != ".."))
						 {
                                
                                if (is_dir($file) && $file !="copieble" && $file !="_vti_cnf") 
                  			     	 {
								    $dst = $path."/".$file."/index.php";
									@copy($filepath,$dst);
								 }
						 }
				   }
				   closedir($handle);
	    
	 }


//  Copy here the index file for all the cities in each states 

      $filepath = $path."/copieble/city/index.php";
     
       if(is_file($filepath))
     {

	 if(is_dir($path))
	    {
              chdir($path); 
		  //echo "<br>".$path."/state";
	      $handle=opendir('.');
                   
		       while (($file = readdir($handle))!==false) 
				   { 
                         
		             if (($file != ".") && ($file != ".."))
						 {
                                
                                if (is_dir($file) && $file != "copieble" && $file !="_vti_cnf") 
                  			     	 {
								    chdir($path."/".$file);
                                        $handle1=opendir('.');
                   
		                               while (($file1 = readdir($handle1))!==false) 
				                           {               
								              if (($file1 != ".") && ($file1 != ".."))
						                         {
                                                        if (is_dir($file1)) 
                  			     	                       {
														 $dst = $path."/".$file."/".$file1."/index.php";
									                     @copy($filepath,$dst);
                         									 
													   }
												 }
										   }
                                          closedir($handle1);  
								 }
                                chdir($path);
						 }
				   }
				   closedir($handle);
	    }
	 }
?>

Link to comment
Share on other sites

If you add this code at the top it should help you find the right variable:

 

print "<pre>"; var_dump($_SERVER); exit;

 

That will show you everything in $_SERVER.  Then you can choose whichever is suitable.  If nothing is suitable you can try `pwd`  (That's pwd in backquotes), and see if that works.  Another option is the getcwd() function.

Link to comment
Share on other sites

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.