0

Hello
I have a php script that resides in a single folder
I want to run the same script in each folder wihout manually uploading the php file in each file

for example I have
mysite.com/folder/script.php

and folder has different subfolders

so I want to create a php file that will execute this script.php in each folder/subfolder without manually uploading the script.php in each folder

Is there a way ?
Please explain how

3
Contributors
5
Replies
6
Views
5 Years
Discussion Span
Last Post by almostbob
0

write in header php file :)

include("../script.php");
  1. mysite.com/folder/script.php
  2. mysite.com/folder/subfolder/testfile.php

    //testfile.php
    include("../script.php");
    //do something

can help you ?

0

I'm assuming you want the php script to act on the subfolders
The google search would be something like "php recursive script"
I have one that I use to make a folder tree of pdf files downloadable, it may provide an insight, it is probably badly written, but functions ok for my purposes

<?php 
function get_Extension($ff){ $path_parts = pathinfo($ff);
 if ($path_parts["extension"]) { $m_Extension = strtoupper($path_parts["extension"]); 
  return($m_Extension);}
 else return("unknown");}
function check_file($ff){$temp=get_Extension($ff);
 if(($temp=="PDF")) return (true);
 else return (false);}
function printQueue($queue, $path) { asort($queue); foreach($queue as $file)    { printFile($file, $path); } }
function printFile($file, $path) { if (check_file($file)) { echo '<li><a href="./savefile.php?file='.$path.$file.'">'.substr($file,0,strlen($file)-4).'</a></li>';}}
function printSubDir($dir, $path) { echo "<li>$dir"; 
 createDir($path.$dir."/"); 
 echo "</li>";}
function createDir($path = './') { if ($handle = opendir($path)){ echo "<div style='margin-bottom:1em;'><ul>";  
 $queue = array();
 while (false !== ($file = readdir($handle))) { if (is_dir($path.$file) && $file != '.' && $file !='..') { printSubDir($file, $path, $queue);}   
  elseif ($file != '.' && $file !='..') {$queue[] = $file;}} 
  printQueue($queue, $path);
  echo "</ul></div>"; }}
createDir(); ?>

savefile.php, referenced in the script is a force-file-download script not required for the recurse function

Edited by almostbob

0

almostbob here is the php script that I want to run in each folder
Actually the script scans the folder and then append it in include.php file which is created automatically so what I want to automatically create that include.php file for each folder

Can you please help?

$path = array("./files/","./images/");
$path2=  array("http://".$_SERVER['SERVER_NAME'].dirname($_SERVER["PHP_SELF"])."/files/","http://".$ _SERVER['SERVER_NAME'].dirname($_SERVER["PHP_SELF"])."/images/");
$start="";
$Fnm = "./include.php";
$inF = fopen($Fnm,"w");
fwrite($inF,$start."\n");

$folder = opendir($path[0]);
while( $file = readdir($folder) ) {
       if (($file != '.')&&($file != '..')&&($file != 'index.htm')) {
            $folder2 = opendir($path[1]);
            $imagename ='';
            while( $file2 = readdir($folder2) ) {
                if (substr($file2,0,strpos($file2,'.')) == substr($file,0,strpos($file,'.'))){
                    $imagename = $file2;
                }
            }
            closedir($folder2);
        $result="{\nlevels: [\n{ file: \"$path2[0]$file\" }\n],\nimage: \"$path2[1]$imagename\",\ntitle: \"$file\"\n},\n";
        fwrite($inF,$result);
       }
}
fwrite($inF,"");
closedir($folder);

fclose($inF);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.