Hej
Jeg har et problem med det her script, primært er det funktionen readDirs() der driller, Jeg kan ikke få den til at udskrive den korrekte sti, hvis jeg har mapperne /et/to/tre udskriver den dem som /et/totre.
Jeg har ud kommenteret en del af koden for nemmere at kunne fejlsøge i det. Men jeg kan ikke rigtig komme videre
- <?php
- $source = "test_source";
- $dest = "Opdateringer/next_release";
- include('Udvikling/admin/inc/config.php');
-
-
- /*
- // CHECK FOR REMOVED FILES
- if(!is_dir($dest.'/admin')){
- mkdir($dest.'/admin');
- }
-
- while($check_removed_data = mysql_fetch_assoc(mysql_query("SELECT * FROM create_release_checsums"))){
- if (file_exists($source.'/'.$check_removed_data['filename']) == FALSE){
- mysql_query("DELETE FROM create_release_checsums WHERE filename='$check_removed_data[filename]'");
- $upgrade_file = fopen($dest.'/admin/upgrade.php', 'a+');
- fwrite($upgrade_file, "unlink('../".$check_removed_data['filename']."'); \n");
- fclose($upgrade_file);
- print '<b>'.$check_removed_data['filename'].'</b> removed from DB and added to update script<br>';
- } else if ($source.'/'.is_dir($check_removed_data['filename'] == FALSE)){
- mysql_query("DELETE FROM create_release_checsums WHERE filename='$check_removed_data[filename]'");
- $upgrade_file = fopen($dest.'/admin/upgrade.php', 'a+');
- fwrite($upgrade_file, "unlink('../".$check_removed_data['filename']."'); \n");
- fclose($upgrade_file);
- print '<b>'.$check_removed_data['filename'].'</b> removed from DB and added to update script<br>';
- }
- }
-
- */
-
- // CHECK FOR NEW FILES AND UPDATES
- function createDirs($main){
- $main = explode("/", $main);
- $dir_strint = "";
- foreach($main as $dir_name){
- if(is_dir($GLOBALS['dest'].'/'.$dir_string.$dir_name) == FALSE){
- mkdir($GLOBALS['dest'].'/'.$dir_string.$dir_name);
- }
- $dir_string = $dir_string.$dir_name.'/';
- }
- }
-
- function readDirs($main){
- $dirHandle = opendir($main);
- while($file = readdir($dirHandle)){
- if ($file != '.' && $file != '..'){
- print $main.$file;
- readDirs($main.'/'.$file);
- //if(is_dir($main.'/'.$file)){
- //if (mysql_num_rows(mysql_query("SELECT * FROM create_release_checsums WHERE filename='$main$file'")) == "0"){
- //mysql_query("INSERT INTO create_release_checsums (filename) VALUES ('$main$file')") or die(mysql_error());
- //$upgrade_file = fopen($GLOBALS['dest'].'/admin/upgrade.php', 'a+');
- //fwrite($upgrade_file, "mkdir('../".$main.$file."'); \n");
- //fclose($upgrade_file);
- //print '<b>'.$file.'</b> added to DB and upgrade file<br>';
- //}
-
- //} else {
- /*
- $md5file = md5_file($file);
- $get_sum = mysql_query("SELECT * FROM create_release_checsums WHERE filename='$main $file'");
- if(mysql_num_rows($get_sum) == '0'){
- // ADD FILE IF NOT EXISTS IN DB
- mysql_query("INSERT INTO create_release_checsums (filename, md5sum) VALUES ('$filename', '$md5filename')") or die(mysql_error());
- createDirs($dest.$main);
- copy($main.$file, $GLOBALS['dest'].'/'.$main.$file);
- print '<b>'.$filename.'</b> added to DB and copied to update folder<br>';
- } else {
- while($get_sum_data = mysql_fetch_assoc($get_sum)){
- if($get_sum_data['md5sum'] != $md5filename){
- mysql_query("UPDATE create_release_checsums SET md5sum='$md5filename' WHERE filename='$filename'") or die(mysql_error());
- $client_string_main = str_replace($GLOBALS['source']."/","", $main);
- createDirs($dest.$main);
- copy($filename, $GLOBALS['dest'].'/'.$main.'/'.$file);
- print '<b>'.$filename.'</b> updated in DB and copied to update folder<br>';
- }
- }
- }
-
- }*/
- }
- }
- }
-
- readDirs($source);
-
- ?>