PHP directory mirroring
I want to mirror a directory through php so i can the files without having to directly modify them.
I found this script (here) but i keep getting a 500 Internal Server Error when i try to set it up.
Could it be because its from 2004?
Are there any other ways to set this up or another method of doing this same thing?
here is some of the code i was using on a shared hosting plan
Agent file
<?php
error_reporting(0);
set_time_limit(0);
function recur_dir($dir)
{
$dirlist = opendir($dir);
while ($file = readdir ($dirlist))
{
if ($file != '.' && $file != '..' && $file != '.DS_Store' && $file != 'mirror_agent.php')
{
$newpath = $dir.'/'.$file;
$permissions = substr(decoct(fileperms($newpath)),-4);
if (is_dir($newpath))
{
echo '
dir|'.$newpath.'|'.$permissions;
recur_dir($newpath);
}else{
echo '
file|'.$newpath.'|'.$permissions.'
'.bin2hex(file_get_contents($newpath));
}
}
}
closedir($dirlist);
return $mod_array;
}
header('Content-type text/plain');
echo 'mirror_agent here';
recur_dir('.');
unlink(__file__);
?>
Client File
<?php
$mirror_agent = 'http://moddline.com/safe/mirror_agent.php';
function hex2asc($temp)
{
for ($i = 0; $i < strlen($temp); $i += 2) $data .= chr(hexdec(substr($temp,$i,2)));
return $data;
}
function file_write($filename, $filecontent, $mode='wb')
{
if($fp = fopen($filename,$mode))
{
fwrite($fp, $filecontent);
fclose($fp);
return true;
}else{
return false;
}
}
error_reporting(0);
set_time_limit(0);
$cont = file_get_contents($mirror_agent);
$files = explode("\n",$cont);
if(trim($files[0]) == 'mirror_agent here' && is_writeable(dirname(__file__)))
{
for($i = 1; $i < count($files); $i++)
{
if(trim($files[$i]) != '')
{
$parts = explode('|',trim($files[$i]));
$permissions = intval($parts[2], 8);
if($parts[0] == 'dir')
{
mkdir($parts[1],$permissions);
$done[] = $permissions.'|'.$parts[1];
}elseif($parts[0] == 'file')
{
file_write($parts[1], hex2asc($files[$i+1]));
chmod($parts[1],$permissions);
$done[] = $permissions.'|'.$parts[1];
$i++;
}
}
}
// output status
echo '
<pre>
following files were copied:';
for($i = 0; $i < count($done); $i++)
{
echo '
'.$done[$i];
}
echo '
</pre>';
unlink(__file__);
}else{
echo '
<pre>
ERROR:
'.$mirror_agent.'
does not respond like a mirror_agent should or
the directory '.dirname开发者_JAVA技巧(__file__).' is not writeable.
</pre>';
}
?>
精彩评论