Copying the same file recursively

Greetings,

What I’d like to do is add the same php file to each directory/sub-directory that is expanded from a zip file. I already have a working unzip class, I want to add this functionality to it. So, image we have a zip file that has the following directory structure:

Foo.zip

FolderA

image1.jpg
image2.jpg
FolderB
image3.jpg
FolderB1

image4.jpg
image5.jpg

Now let’s say I have a php file (viewer.php) which is an image gallery script. What I want is after the zip extracts it places this php file in each directory so that I can view the images automatically from my browser. So the directory structure on my server would look like this after the unzip script has run:

Foo.zip

FolderA

image1.jpg
image2.jpg
viewer.php
FolderB
image3.jpg
viewer.php
FolderB1

image4.jpg
image5.jpg
viewer.php

I’ve Googled my heart out trying to find how to copy a single file recursively and at least for me, I can’t seem to find an answer. Any thoughts/suggestions?

Thanks in advance!

if it is the same file i woudn’t use it multible times.

have u heard of the rewrite engine?

use a .htacces file and put some code in there like (just an untested example):

RewriteEngine On RewriteRule (.*)/viewer.php /viewer.php?dir=$1 [QSA,L]

that way u may use just one viewer.php but inside that $_GET[‘dir’] can be used to display the img’s of the folder used. (just use $_GET[‘dir’] for the img list, don’t use it as part of the src-atribute of the img-tag as the browser still “thinks” it is inside that dir)

Q1712,

Thanks for the suggestion…I will look into that approach. However, I would still like to learn how to do what I talked about in the OP. If you or anyone else has any suggestions, they would be appreciated.

Thanks.

if u just need to copy that file to all subdirs u may use somthing like this (not tested):
[php]<?php
function subdirs($dir=’.’)
{
$dirs=array();
$mydir = dir($dir);
while(($file = $mydir->read()) !== false)
{
if(is_dir($mydir->path.’/’.$file) == true && $file != ‘.’ && $file != ‘…’)
{
$dirs[]=$mydir->path.’/’.$file.’/’;
$dirs=array_merge($dirs,subdirs($mydir->path.’/’.$file));
}
}
$mydir->close();
return $dirs;
}

$subdirs=subdirs(‘path2unzipedfiles’);

foreach($subdirs as $subdir)
{
copy(‘viewer.php’,$subdir.‘viewer.php’);
}
?>[/php]
thx2george

but i still suggest not having the same file multible times.

Q1712,

I think I’ve got it with that…thanks!

edited my previous post. had some .’/’ missing.

Sponsor our Newsletter | Privacy Policy | Terms of Service