Created
April 18, 2018 14:40
-
-
Save kazimolmez/e22c8da0ec8d636ac5dabb61d4f5e7e9 to your computer and use it in GitHub Desktop.
PHP Rename Files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="tr"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" | |
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<link rel="author" href="http://www.kazimolmez.com" /> | |
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> | |
<title>Rename Files</title> | |
<style> | |
.alert { | |
padding: 2px; | |
margin-bottom:5px; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="container"> | |
<?php | |
function url_title($str) | |
{ | |
$separator = '-'; | |
$trCharters = array('Ü', 'ü', 'Ğ', 'ğ', 'Ş', 'ş', 'İ', 'ı', 'Ç', 'ç', 'Ö', 'ö'); | |
$enCharters = array('U', 'u', 'G', 'g', 'S', 's', 'I', 'i', 'C', 'c', 'O', 'o'); | |
$str = str_replace($trCharters, $enCharters, $str); | |
$str = str_replace(" ", $separator, $str); | |
$str = strip_tags($str); | |
$str = strtolower($str); | |
return trim(trim($str, $separator)); | |
} | |
$files=glob("upload/products/*.jpg", GLOB_BRACE); | |
?> | |
Toplam: <?=count($files)?> | |
<?php | |
if(count($files)!=0){ | |
$i = 1; | |
foreach($files as $file) { | |
if (rename($file, url_title(str_replace('products', 'products_new', $file)))) { | |
echo '<div class="alert alert-success">'.$i . ' - ' . $file.'</div>'; | |
} else { | |
echo '<div class="alert alert-danger">'.$i . ' - ' . $file.'</div>'; | |
} | |
++$i; | |
} | |
} | |
?> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment