1
0
Fork 0
This commit is contained in:
Ziver Koc 2010-11-04 15:40:50 +00:00
parent 629114bac5
commit bece225d84
5 changed files with 381 additions and 381 deletions

View file

@ -1,94 +1,94 @@
<?php <?php
require_once("info.php"); require_once("info.php");
/* /*
trigger_error("Incorrect input vector, array of values expected", E_USER_WARNING); trigger_error("Incorrect input vector, array of values expected", E_USER_WARNING);
Value Constant Description Value Constant Description
1 E_ERROR (integer) Fatal run-time errors. These indicate errors that can not be recovered from, such as a memory allocation problem. Execution of the script is halted. 1 E_ERROR (integer) Fatal run-time errors. These indicate errors that can not be recovered from, such as a memory allocation problem. Execution of the script is halted.
2 E_WARNING (integer) Run-time warnings (non-fatal errors). Execution of the script is not halted. 2 E_WARNING (integer) Run-time warnings (non-fatal errors). Execution of the script is not halted.
4 E_PARSE (integer) Compile-time parse errors. Parse errors should only be generated by the parser. 4 E_PARSE (integer) Compile-time parse errors. Parse errors should only be generated by the parser.
8 E_NOTICE (integer) Run-time notices. Indicate that the script encountered something that could indicate an error, but could also happen in the normal course of running a script. 8 E_NOTICE (integer) Run-time notices. Indicate that the script encountered something that could indicate an error, but could also happen in the normal course of running a script.
16 E_CORE_ERROR (integer) Fatal errors that occur during PHP's initial startup. This is like an E_ERROR, except it is generated by the core of PHP. 16 E_CORE_ERROR (integer) Fatal errors that occur during PHP's initial startup. This is like an E_ERROR, except it is generated by the core of PHP.
32 E_CORE_WARNING (integer) Warnings (non-fatal errors) that occur during PHP's initial startup. This is like an E_WARNING, except it is generated by the core of PHP. 32 E_CORE_WARNING (integer) Warnings (non-fatal errors) that occur during PHP's initial startup. This is like an E_WARNING, except it is generated by the core of PHP.
64 E_COMPILE_ERROR (integer) Fatal compile-time errors. This is like an E_ERROR, except it is generated by the Zend Scripting Engine. 64 E_COMPILE_ERROR (integer) Fatal compile-time errors. This is like an E_ERROR, except it is generated by the Zend Scripting Engine.
128 E_COMPILE_WARNING (integer) Compile-time warnings (non-fatal errors). This is like an E_WARNING, except it is generated by the Zend Scripting Engine. 128 E_COMPILE_WARNING (integer) Compile-time warnings (non-fatal errors). This is like an E_WARNING, except it is generated by the Zend Scripting Engine.
256 E_USER_ERROR (integer) User-generated error message. This is like an E_ERROR, except it is generated in PHP code by using the PHP function trigger_error(). 256 E_USER_ERROR (integer) User-generated error message. This is like an E_ERROR, except it is generated in PHP code by using the PHP function trigger_error().
512 E_USER_WARNING (integer) User-generated warning message. This is like an E_WARNING, except it is generated in PHP code by using the PHP function trigger_error(). 512 E_USER_WARNING (integer) User-generated warning message. This is like an E_WARNING, except it is generated in PHP code by using the PHP function trigger_error().
1024 E_USER_NOTICE (integer) User-generated notice message. This is like an E_NOTICE, except it is generated in PHP code by using the PHP function trigger_error(). 1024 E_USER_NOTICE (integer) User-generated notice message. This is like an E_NOTICE, except it is generated in PHP code by using the PHP function trigger_error().
2048 E_STRICT (integer) Run-time notices. Enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code. 2048 E_STRICT (integer) Run-time notices. Enable to have PHP suggest changes to your code which will ensure the best interoperability and forward compatibility of your code.
4096 E_RECOVERABLE_ERROR (integer) Catchable fatal error. It indicates that a probably dangerous error occured, but did not leave the Engine in an unstable state. If the error is not caught by a user defined handle (see also set_error_handler()), the application aborts as it was an E_ERROR. 4096 E_RECOVERABLE_ERROR (integer) Catchable fatal error. It indicates that a probably dangerous error occured, but did not leave the Engine in an unstable state. If the error is not caught by a user defined handle (see also set_error_handler()), the application aborts as it was an E_ERROR.
8191 E_ALL (integer) All errors and warnings, as supported, except of level E_STRICT in PHP < 6. 8191 E_ALL (integer) All errors and warnings, as supported, except of level E_STRICT in PHP < 6.
HTML HTML
<div id="info" style="border:2px solid {'message_color_border'}; padding:5px;margin:10px;background:{'message_color'} none repeat scroll 0%;font-size:13px;"> <div id="info" style="border:2px solid {'message_color_border'}; padding:5px;margin:10px;background:{'message_color'} none repeat scroll 0%;font-size:13px;">
<center>{'message'}</center> <center>{'message'}</center>
</div> </div>
*/ */
$errors = array(); $errors = array();
set_error_handler("errorHandler"); set_error_handler("errorHandler");
register_shutdown_function("printErrors"); register_shutdown_function("printErrors");
if(isset($language["error_unknown"])) $language["error_unknown"] = "Unknown Error Type"; if(isset($language["error_unknown"])) $language["error_unknown"] = "Unknown Error Type";
if(isset($language["error"])) $language["error"] = "Error"; if(isset($language["error"])) $language["error"] = "Error";
if(isset($language["warning"])) $language["warning"] = "Warning"; if(isset($language["warning"])) $language["warning"] = "Warning";
// error handler function // error handler function
function errorHandler($errno, $errstr, $errfile, $errline){ function errorHandler($errno, $errstr, $errfile, $errline){
GLOBAL $language,$errors; GLOBAL $language,$errors;
$info = new Info(); $info = new Info();
switch ($errno) { switch ($errno) {
case E_ERROR: case E_ERROR:
case E_USER_ERROR: case E_USER_ERROR:
$err = buildError($language["error"],$errno, $errstr, $errfile, $errline); $err = buildError($language["error"],$errno, $errstr, $errfile, $errline);
$errors[] = $info->buildMessage($err,"error"); $errors[] = $info->buildMessage($err,"error");
//dbSaveLog(getURL(),$err,date("Y-m-d H:i:s")); //dbSaveLog(getURL(),$err,date("Y-m-d H:i:s"));
break; break;
case E_WARNING: case E_WARNING:
case E_USER_WARNING: case E_USER_WARNING:
$err = buildError($language["warning"],$errno, $errstr, $errfile, $errline); $err = buildError($language["warning"],$errno, $errstr, $errfile, $errline);
$errors[] = $info->buildMessage($err,"warning"); $errors[] = $info->buildMessage($err,"warning");
//dbSaveLog(getURL(),$err,date("Y-m-d H:i:s")); //dbSaveLog(getURL(),$err,date("Y-m-d H:i:s"));
break; break;
case E_NOTICE: case E_NOTICE:
case E_USER_NOTICE: case E_USER_NOTICE:
//$err = buildError($language["error_unknown"],$errno, $errstr, $errfile, $errline); //$err = buildError($language["error_unknown"],$errno, $errstr, $errfile, $errline);
//dbSaveLog(getURL(),$err,date("Y-m-d H:i:s")); //dbSaveLog(getURL(),$err,date("Y-m-d H:i:s"));
break; break;
default: default:
$err = buildError($language["error_unknown"],$errno, $errstr, $errfile, $errline); $err = buildError($language["error_unknown"],$errno, $errstr, $errfile, $errline);
$errors[] = $info->buildMessage($err,"error"); $errors[] = $info->buildMessage($err,"error");
//dbSaveLog(getURL(),$err,date("Y-m-d H:i:s")); //dbSaveLog(getURL(),$err,date("Y-m-d H:i:s"));
break; break;
} }
/* Don't execute PHP internal error handler */ /* Don't execute PHP internal error handler */
return true; return true;
} }
function buildError($errhead,$errno, $errstr, $errfile, $errline){ function buildError($errhead,$errno, $errstr, $errfile, $errline){
GLOBAL $config; GLOBAL $config;
//[$errno] //[$errno]
if(!isset($config["debug"]) || $config["debug"]) if(!isset($config["debug"]) || $config["debug"])
$error = "<strong>$errhead:</strong> $errfile($errline)<br /><b>$errstr</b>"; $error = "<strong>$errhead:</strong> $errfile($errline)<br /><b>$errstr</b>";
else else
$error = "<strong>$errhead: </strong>$errstr"; $error = "<strong>$errhead: </strong>$errstr";
return $error; return $error;
} }
function getErrors(){ function getErrors(){
GLOBAL $errors; GLOBAL $errors;
if(empty($errors)) return ""; if(empty($errors)) return "";
$temp = ""; $temp = "";
foreach($errors as $one){ foreach($errors as $one){
$temp .= $one; $temp .= $one;
} }
$errors = array(); $errors = array();
return $temp; return $temp;
} }
function printErrors(){ function printErrors(){
echo getErrors(); echo getErrors();
} }
?> ?>

View file

@ -1,34 +1,34 @@
<?php <?php
require_once("template.php"); require_once("template.php");
class Info{ class Info{
var $type = array ( var $type = array (
"warning" => array("#F0FF69","#FFFB3E"), "warning" => array("#F0FF69","#FFFB3E"),
"error" => array("#FFDDCC","#FF0000"), "error" => array("#FFDDCC","#FF0000"),
"info" => array("#9BFB66","#039C00") "info" => array("#9BFB66","#039C00")
); );
var $defaultStyle = " var $defaultStyle = "
<div id=\"info\" style=\"border:2px solid {'message_color_border'}; padding:5px;margin:10px;background:{'message_color'} none repeat scroll 0%;font-size:13px;\"> <div id=\"info\" style=\"border:2px solid {'message_color_border'}; padding:5px;margin:10px;background:{'message_color'} none repeat scroll 0%;font-size:13px;\">
<center>{'message'}</center> <center>{'message'}</center>
</div> </div>
"; ";
function buildMessage($msg, $t="warning"){ function buildMessage($msg, $t="warning"){
GLOBAL $template; GLOBAL $template;
if(isset($template["message"])){ if(isset($template["message"])){
$temp = new Template($template["message"]); $temp = new Template($template["message"]);
} }
else{ else{
$temp = new Template($this->defaultStyle); $temp = new Template($this->defaultStyle);
} }
$temp->replace_tags(array( $temp->replace_tags(array(
"message_color" => $this->type[$t][0], "message_color" => $this->type[$t][0],
"message_color_border" => $this->type[$t][1], "message_color_border" => $this->type[$t][1],
"message" => $msg "message" => $msg
)); ));
return $temp->getOutput(); return $temp->getOutput();
} }
} }
?> ?>

View file

@ -1,35 +1,35 @@
<?php <?php
class Template{ class Template{
var $page; var $page;
function Template($template = "HelloWorld!!!") { function Template($template = "HelloWorld!!!") {
$this->page = $template; $this->page = $template;
} }
function replace_tags($tags = array()) { function replace_tags($tags = array()) {
if (sizeof($tags) > 0) if (sizeof($tags) > 0)
foreach ($tags as $tag => $data) { foreach ($tags as $tag => $data) {
//$data = (file_exists($data)) ? $this->parse($data) : $data; //$data = (file_exists($data)) ? $this->parse($data) : $data;
$this->page = str_ireplace("{'" . $tag . "'}", $data, $this->page);//eregi_replace $this->page = str_ireplace("{'" . $tag . "'}", $data, $this->page);//eregi_replace
} }
else else
die("No tags designated for replacement."); die("No tags designated for replacement.");
} }
function output() { function output() {
echo $this->page; echo $this->page;
} }
function getOutput() { function getOutput() {
return $this->page; return $this->page;
} }
function parse($file) { function parse($file) {
ob_start(); ob_start();
include($file); include($file);
$buffer = ob_get_contents(); $buffer = ob_get_contents();
ob_end_clean(); ob_end_clean();
return $buffer; return $buffer;
} }
} }
?> ?>

134
db.php
View file

@ -1,68 +1,68 @@
<?php <?php
$db_host = "koc.se"; $db_host = "koc.se";
$db_database = ""; $db_database = "";
$db_user = ""; $db_user = "";
$db_password = ""; $db_password = "";
function dbconnect(){ function dbconnect(){
@mysql_pconnect($GLOBALS['db_host'],$GLOBALS['db_user'],$GLOBALS['db_password']) @mysql_pconnect($GLOBALS['db_host'],$GLOBALS['db_user'],$GLOBALS['db_password'])
or die("ERROR CONNECTING TO DATABASE ".$GLOBALS['db_host']."!!!"); or die("ERROR CONNECTING TO DATABASE ".$GLOBALS['db_host']."!!!");
@mysql_select_db($GLOBALS['db_database']) @mysql_select_db($GLOBALS['db_database'])
or die("THE DATABASE <b>".$GLOBALS['db_database']."</b> DO NOT EXIST!!!"); or die("THE DATABASE <b>".$GLOBALS['db_database']."</b> DO NOT EXIST!!!");
} }
function dbdisconnect(){ function dbdisconnect(){
@mysql_close(); @mysql_close();
} }
function getTableRow($table, $id){ function getTableRow($table, $id){
$sqlSats = "SELECT * FROM ".$table." WHERE id=".$id; $sqlSats = "SELECT * FROM ".$table." WHERE id=".$id;
return runSimpleQuery($sqlSats); return runSimpleQuery($sqlSats);
} }
function getTableCount($table){ function getTableCount($table){
$sqlSats = "SELECT * FROM ".$table; $sqlSats = "SELECT * FROM ".$table;
return runSimpleQuery($sqlSats); return runSimpleQuery($sqlSats);
} }
function getDBLastUpdateTime(){ function getDBLastUpdateTime(){
$query = runQueryArray("SHOW TABLE STATUS"); $query = runQueryArray("SHOW TABLE STATUS");
foreach($query as $row){ foreach($query as $row){
if(empty($ret) || $row["Update_time"] > $ret){ if(empty($ret) || $row["Update_time"] > $ret){
$ret = $row["Update_time"]; $ret = $row["Update_time"];
} }
} }
return date("D F o H:i",strtotime($ret)); return date("D F o H:i",strtotime($ret));
} }
function dbSaveLog($url,$message,$date){ function dbSaveLog($url,$message,$date){
runSimpleQuery("INSERT INTO log VALUES (null,'$url','$message','$date')"); runSimpleQuery("INSERT INTO log VALUES (null,'$url','$message','$date')");
} }
function runQueryArray($sqlSats){ function runQueryArray($sqlSats){
$resultat = array(); $resultat = array();
$sql = @mysql_query($sqlSats); $sql = @mysql_query($sqlSats);
if($sql == false){ if($sql == false){
trigger_error("ARRAY QUERY FAILD: \"".$sqlSats."\"", E_USER_ERROR); trigger_error("ARRAY QUERY FAILD: \"".$sqlSats."\"", E_USER_ERROR);
die(); die();
} }
while ($row = mysql_fetch_array($sql,MYSQL_ASSOC)){ while ($row = mysql_fetch_array($sql,MYSQL_ASSOC)){
array_push($resultat, $row); array_push($resultat, $row);
} }
return $resultat; return $resultat;
} }
function runSimpleQuery($sqlSats){ function runSimpleQuery($sqlSats){
$resultat = @mysql_query($sqlSats); $resultat = @mysql_query($sqlSats);
if($resultat == false){ if($resultat == false){
trigger_error("QUERY FAILD: \"".$sqlSats."\"", E_USER_ERROR); trigger_error("QUERY FAILD: \"".$sqlSats."\"", E_USER_ERROR);
die(); die();
} }
if(is_bool($resultat) || is_int($resultat)) if(is_bool($resultat) || is_int($resultat))
return $resultat; return $resultat;
else else
return @mysql_fetch_assoc($resultat); return @mysql_fetch_assoc($resultat);
} }
?> ?>

306
sync.php
View file

@ -1,153 +1,153 @@
<?php <?php
$sync = true; $sync = true;
$localDir = "projects"; $localDir = "projects";
$remoteFileSyncURL = "http://www.nada.kth.se/~ziver/sync.php"; $remoteFileSyncURL = "http://www.nada.kth.se/~ziver/sync.php";
$skip_filetype = array ("..","."); $skip_filetype = array ("..",".");
$sessionPassword = "lol"; $sessionPassword = "lol";
if(isset($_GET["fileList"])){ if(isset($_GET["fileList"])){
if($_GET["fileList"] == "array") print_r(getFileArray($localDir)); if($_GET["fileList"] == "array") print_r(getFileArray($localDir));
else echo serialize(getFileArray($localDir)); else echo serialize(getFileArray($localDir));
} }
else if(isset($_GET["copyid"]) && $sync){ else if(isset($_GET["copyid"]) && $sync){
session_start(); session_start();
if($_SESSION['auth'] == $sessionPassword){ if($_SESSION['auth'] == $sessionPassword){
echo " echo "
<html> <html>
<body onload='stop = true;'> <body onload='stop = true;'>
<div id='load'>|</div> <div id='load'>|</div>
<script language='javascript'> <script language='javascript'>
var stop = false; var stop = false;
function load() { function load() {
var loading = document.getElementById('load'); var loading = document.getElementById('load');
if (loading.innerHTML == '-') { if (loading.innerHTML == '-') {
loading.innerHTML = '\\\\'; loading.innerHTML = '\\\\';
} }
else if(loading.innerHTML == '\\\\'){ else if(loading.innerHTML == '\\\\'){
loading.innerHTML = '|'; loading.innerHTML = '|';
} }
else if(loading.innerHTML == '|'){ else if(loading.innerHTML == '|'){
loading.innerHTML = '/'; loading.innerHTML = '/';
} }
else if(loading.innerHTML == '/'){ else if(loading.innerHTML == '/'){
loading.innerHTML = '-'; loading.innerHTML = '-';
} }
if(stop){ if(stop){
loading.innerHTML = 'OK'; loading.innerHTML = 'OK';
return; return;
} }
setTimeout('load()',200); setTimeout('load()',200);
} }
load(); load();
</script> </script>
</body> </body>
</html> </html>
"; ";
flush(); flush();
copyFile($_SESSION["id".$_GET["copyid"]]["copy"],$_SESSION["id".$_GET["copyid"]]["to"],$_SESSION["id".$_GET["copyid"]]["date"]); copyFile($_SESSION["id".$_GET["copyid"]]["copy"],$_SESSION["id".$_GET["copyid"]]["to"],$_SESSION["id".$_GET["copyid"]]["date"]);
} }
else{ else{
echo "<font color=red>ERROR</font>"; echo "<font color=red>ERROR</font>";
} }
} }
else if($sync){ else if($sync){
session_start(); session_start();
$_SESSION['auth'] = $sessionPassword; $_SESSION['auth'] = $sessionPassword;
$sessionId = 0; $sessionId = 0;
$remoteFileList = unserialize(file_get_contents($remoteFileSyncURL."?fileList")); $remoteFileList = unserialize(file_get_contents($remoteFileSyncURL."?fileList"));
$localFileList = getFileArray($localDir); $localFileList = getFileArray($localDir);
echo "<center><b>KOC SYNC: </b>".$remoteFileSyncURL."<br /><table width='200' border='1' style='border:1px solid #CCCCCC; border-collapse:collapse; width:95%;'>"; echo "<center><b>KOC SYNC: </b>".$remoteFileSyncURL."<br /><table width='200' border='1' style='border:1px solid #CCCCCC; border-collapse:collapse; width:95%;'>";
foreach($remoteFileList as $remoteFile){ foreach($remoteFileList as $remoteFile){
$temp = searchFile($remoteFile, $localFileList); $temp = searchFile($remoteFile, $localFileList);
if($temp >= 0){ if($temp >= 0){
if($remoteFile[0] > $localFileList[$temp][0]){ if($remoteFile[0] > $localFileList[$temp][0]){
$_SESSION["id".$sessionId]["copy"] = $remoteFile[2]; $_SESSION["id".$sessionId]["copy"] = $remoteFile[2];
$_SESSION["id".$sessionId]["to"] = $localDir.$localFileList[$temp][1]; $_SESSION["id".$sessionId]["to"] = $localDir.$localFileList[$temp][1];
$_SESSION["id".$sessionId]["date"] = $remoteFile[0]; $_SESSION["id".$sessionId]["date"] = $remoteFile[0];
echo "<tr bgcolor='#FF6F5C'><td>Local File Old!</td><td><iframe src='sync.php?copyid=".$sessionId."' width='25' height='20' frameborder='0' marginwidth='0' marginheight='0'></iframe></td>"; echo "<tr bgcolor='#FF6F5C'><td>Local File Old!</td><td><iframe src='sync.php?copyid=".$sessionId."' width='25' height='20' frameborder='0' marginwidth='0' marginheight='0'></iframe></td>";
$sessionId++; $sessionId++;
//copyFile($remoteFile[2],$localDir.$localFileList[$temp][1], $remoteFile[0]); //copyFile($remoteFile[2],$localDir.$localFileList[$temp][1], $remoteFile[0]);
} }
else if($remoteFile[0] < $localFileList[$temp][0]){ else if($remoteFile[0] < $localFileList[$temp][0]){
echo "<tr bgcolor='#A9B4FF'><td>Local File Newer!</td><td></td>"; echo "<tr bgcolor='#A9B4FF'><td>Local File Newer!</td><td></td>";
} }
else{ else{
echo "<tr><td>Synced!</td><td></td>"; echo "<tr><td>Synced!</td><td></td>";
} }
} }
else{ else{
$_SESSION["id".$sessionId]["copy"] = $remoteFile[2]; $_SESSION["id".$sessionId]["copy"] = $remoteFile[2];
$_SESSION["id".$sessionId]["to"] = $localDir.$remoteFile[1]; $_SESSION["id".$sessionId]["to"] = $localDir.$remoteFile[1];
$_SESSION["id".$sessionId]["date"] = $remoteFile[0]; $_SESSION["id".$sessionId]["date"] = $remoteFile[0];
echo "<tr bgcolor='#89FF8B'><td>New File!</td><td><iframe src='sync.php?copyid=".$sessionId."' width='25' height='20' frameborder='0' marginwidth='0' marginheight='0'></iframe></td>"; echo "<tr bgcolor='#89FF8B'><td>New File!</td><td><iframe src='sync.php?copyid=".$sessionId."' width='25' height='20' frameborder='0' marginwidth='0' marginheight='0'></iframe></td>";
$sessionId++; $sessionId++;
//copyFile($remoteFile[2],$localDir.$remoteFile[1],$remoteFile[0]); //copyFile($remoteFile[2],$localDir.$remoteFile[1],$remoteFile[0]);
} }
echo "<td>".$remoteFile[2]."</td><td> => </td><td>".$remoteFile[1]."</td></tr>"; echo "<td>".$remoteFile[2]."</td><td> => </td><td>".$remoteFile[1]."</td></tr>";
} }
echo "</table></center>"; echo "</table></center>";
} }
else { else {
echo"<center><font color=red>Sync disabled for this server!</font></center>"; echo"<center><font color=red>Sync disabled for this server!</font></center>";
} }
function copyFile($source,$dest, $lastModDate = null){ function copyFile($source,$dest, $lastModDate = null){
@$file = fopen ($source, "rb"); @$file = fopen ($source, "rb");
if (!$file) { if (!$file) {
echo"<font color=red>Failed to copy $source -> $dest!</font><br>"; echo"<font color=red>Failed to copy $source -> $dest!</font><br>";
return false; return false;
}else { }else {
if(!file_exists(dirname($dest))) if(!file_exists(dirname($dest)))
mkdir(dirname($dest),0777,true); mkdir(dirname($dest),0777,true);
$filename = basename($source); $filename = basename($source);
$fc = fopen($dest, "wb"); $fc = fopen($dest, "wb");
echo "<font color=green>$source => $dest</font><br><font color=black>"; echo "<font color=green>$source => $dest</font><br><font color=black>";
while (!feof ($file)) { while (!feof ($file)) {
$line = fread ($file, 1028); $line = fread ($file, 1028);
fwrite($fc,$line); fwrite($fc,$line);
echo "#"; echo "#";
} }
fclose($fc); fclose($fc);
if($lastModDate != null) touch($dest,$lastModDate); if($lastModDate != null) touch($dest,$lastModDate);
echo "</font><br>"; echo "</font><br>";
return true; return true;
} }
} }
$tempFilesArray = array(); $tempFilesArray = array();
function getFileArray($foldername) { function getFileArray($foldername) {
GLOBAL $localDir, $skip_filetype, $tempFilesArray; GLOBAL $localDir, $skip_filetype, $tempFilesArray;
$dirhandle = @opendir($foldername); //öppnar mappen $dirhandle = @opendir($foldername); //öppnar mappen
if($dirhandle !== false){ //gick det att öppna mappen? if($dirhandle !== false){ //gick det att öppna mappen?
while($filename = readdir($dirhandle)){ //loopar igenom alla filer i mappen while($filename = readdir($dirhandle)){ //loopar igenom alla filer i mappen
$filepath = $foldername ."/". $filename; $filepath = $foldername ."/". $filename;
if($filename != "." && $filename != ".." && is_dir($filepath)){ //är det en mapp? if($filename != "." && $filename != ".." && is_dir($filepath)){ //är det en mapp?
getFileArray($filepath); getFileArray($filepath);
} }
else{ // its a file else{ // its a file
$filetype = ereg_replace("^.+\\.([^.]+)$", "\\1", $filename); $filetype = ereg_replace("^.+\\.([^.]+)$", "\\1", $filename);
if (!in_array($filetype, $skip_filetype)) { if (!in_array($filetype, $skip_filetype)) {
$tempFilesArray[] = array(filemtime($filepath),str_replace($localDir, "", $filepath),("http://".$_SERVER['SERVER_NAME'].str_replace("sync.php","",$_SERVER['SCRIPT_NAME']).$filepath),$filename); $tempFilesArray[] = array(filemtime($filepath),str_replace($localDir, "", $filepath),("http://".$_SERVER['SERVER_NAME'].str_replace("sync.php","",$_SERVER['SCRIPT_NAME']).$filepath),$filename);
} }
} }
} }
} }
return $tempFilesArray; return $tempFilesArray;
} }
function searchFile($remoteFile, $localFileList){ function searchFile($remoteFile, $localFileList){
if(isset($localFileList)){ if(isset($localFileList)){
foreach($localFileList as $key => $localFile){ foreach($localFileList as $key => $localFile){
if($localFile[1] == $remoteFile[1]){ if($localFile[1] == $remoteFile[1]){
return $key; return $key;
} }
} }
} }
return -1; return -1;
} }
?> ?>