Jump to content

Defcont4

New Members
  • Posts

    1
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Defcont4's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I write a function to open a folder and look the images names of the folder and rename if necessary. But the fuction only work alone, when I joiner with the function that open and search the files it dont rename anything. The folder structure: /public_html/mangas/Teste 01/001 Alone: <?php function normalize($string) { $table = array( 'Š'=>'S', 'š'=>'s', 'Đ'=>'Dj', 'đ'=>'dj', 'Ž'=>'Z', 'ž'=>'z', 'Č'=>'C', 'č'=>'c', 'Ć'=>'C', 'ć'=>'c', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E', 'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U', 'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss', 'à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c', 'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y', 'Ŕ'=>'R', 'ŕ'=>'r', '#'=>'', '!'=>'', '?'=>'', ','=>'', '~'=>'', '@'=>'', '%'=>'', '$'=>'', '¨'=>'', '*'=>'', 'º'=>'', '§'=>'', '°'=>'', "'"=>"", 'ƒ'=>'f', '&'=>'', '['=>'', ']'=>'', '('=>'', ')'=>'', '{'=>'', '}'=>'', 'ª'=>'', ' '=>'-', '/'=>'-' ); $rsult = array(); $rsult["name"] = strtr($string, $table); if ($rsult["name"] != $string) { $rsult["set"] = true; } else { $rsult["set"] = false; } return $rsult; } $test = "2ç2.png"; $n_name = normalize($test); if ($n_name["set"]) { echo $test." --> ".$n_name["name"]; } else { echo $test; } ?> Final script: <?php function normalize($string) { $table = array( 'Š'=>'S', 'š'=>'s', 'Đ'=>'Dj', 'đ'=>'dj', 'Ž'=>'Z', 'ž'=>'z', 'Č'=>'C', 'č'=>'c', 'Ć'=>'C', 'ć'=>'c', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E', 'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U', 'Ú'=>'U', 'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss', 'à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 'å'=>'a', 'æ'=>'a', 'ç'=>'c', 'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y', 'Ŕ'=>'R', 'ŕ'=>'r', '#'=>'', '!'=>'', '?'=>'', ','=>'', '~'=>'', '@'=>'', '%'=>'', '$'=>'', '¨'=>'', '*'=>'', 'º'=>'', '§'=>'', '°'=>'', "'"=>"", 'ƒ'=>'f', '&'=>'', '['=>'', ']'=>'', '('=>'', ')'=>'', '{'=>'', '}'=>'', 'ª'=>'', ' '=>'-', '/'=>'-' ); $rsult = array(); $rsult["name"] = strtr($string, $table); if ($rsult["name"] != $string) { $rsult["set"] = 1; } else { $rsult["set"] = 2; } return $rsult; } function clearName($a, $b) { $a = str_replace('_', ' ', $a); $b = str_replace('_', ' ', $b); $counter = 0; $counter2 = 0; $counter3 = 0; $counter4 = 0; $folder = "mangas/".$a."/".$b; $current_dir = dirname(__FILE__); $a = str_replace(' ', '_', $a); $b = str_replace(' ', '_', $b); $dbHost = 'localhost'; $dbUser = 'root'; $dbPass = 'pass'; $dbDatabase = 'db'; $con = mysql_connect($dbHost, $dbUser, $dbPass); mysql_select_db($dbDatabase); $handle = @opendir(''.$folder.''); if (!$handle) { $set2 = 4; } else { while (false !== ($file = readdir($handle))) { if (strpos($file, '.jpeg',1) OR strpos($file, '.jpg',1) OR strpos($file, '.gif',1) OR strpos($file, '.png',1) OR strpos($file, '.JPEG',1) OR strpos($file, '.JPG',1) OR strpos($file, '.GIF',1) OR strpos($file, '.PNG',1)) { $counter++; $path = $current_dir."/".$folder."/"; $n_name = normalize($file); if ($n_name["set"] == 1) { if (rename($path.$file, $path.$n_name["name"])) { $counter2++; echo $file." --> ".$n_name["name"]."<br /><br />\n\n"; } else { $counter3++; echo "ERROR --> Could not rename \"".$file."\"<br /><br />\n\n"; $sql2 = "INSERT INTO corrupt (titulo, cap, pag) VALUES ('".$a."', '".$b."', '".$file."')"; $sql2 = @mysql_query($sql2, $con); if (!$sql2) { echo "<b>Error:</b> SQL Error -> &#36;sql2: \"".$sql2."\"<br /><br />\n\n"; } } } else { $counter4++; echo $file."<br /><br />\n\n"; } } } closedir($handle); if ($counter == 0) { $set2 = 6; } } //Error if($set2 == 4) { $sql3 = "INSERT INTO error (titulo, cap, tipo) VALUES ('".$a."', '".$b."', '4')"; $msql3 = "<b>Folder Error:</b> (#4) Could not be open folder or don't exist!<br /><br />\n\n"; //Error #2 } elseif($set2 == 6) { $sql3 = "INSERT INTO error (titulo, cap, tipo) VALUES ('".$a."', '".$b."', '6')"; $msql3 = "<b>Folder Error:</b> (#6) Could not find any image!<br /><br />\n\n"; } if (isset($sql3)) { $sql3 = @mysql_query($sql3, $con); if (!$sql3) { echo "<b>Error:</b> (#".$set2.") SQL Error -> &#36;sql3: \"".$sql3."\"<br /><br />\n\n"; } else { echo $msql3; } } echo "<b>Total Files:</b> ".$counter." <br /><br />\n"; echo "<b>| Files Renamed:</b> ".$counter2." <br /><br />\n"; echo "<b>| Files Rename Fail:</b> ".$counter3." <br /><br />\n"; echo "<b>| Files Good TO Go:</b> ".$counter4." <br /><br />\n"; } $manga = "Teste_01"; $cap = "001"; clearName($manga, $cap); ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.