-4
システム内のアップロードファイルに大括弧を取り除く際に問題があります。PHP:ディレクトリおよびすべてのサブディレクトリ内のファイル名から括弧を再帰的に削除します。
私は単一のディレクトリのファイルで角括弧を削除することができますが、私は同じフォルダのサブディレクトリに再帰的にこの作業を取得するのに苦労しています。
私はstr_replaceを使用して角括弧[]を見つけ、空白文字で置き換えています。
$dir = $_SERVER["DOCUMENT_ROOT"]."/uploads" ; // what directory to parse
if ($handle = opendir ($dir)) {
print "Directory Handle = $handles\n" ;
print "Files : \n" ;
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$isdir = is_dir ($file) ;
if ($isdir == "1") {} // if its a directory do nothing
else {
$file_array[] = "$file" ; // get all the file names and put them in an array
print "$file\n" ;
} // closes else
} // closes directory check
} // closes while
} // closes opendir
//Lets go through the array
$arr_count = count($file_array) ; // find out how many files we have found so we can initiliase the counter
for ($counter=1; $counter<$arr_count; $counter++) {
print "Array = $file_array[$counter]\n" ; // tell me how many files there are
$illegals = array("[","]");
$new = str_replace ($illegals, "", $file_array[$counter]) ; // now create the new file name
$ren = rename ("$dir/$file_array[$counter]" , "$dir/$new") ; // now do the actual file rename
print "$new\n" ; // print out the new file name
}
closedir ($handle) ;
echo $dir;
"私は現在コードを見つけることができませんが、後でアップロードします。" OK、私は待つよ... – nogad
[PHP:ディレクトリ内のすべてのファイルの名前を再帰的に小文字に変更する](https://stackoverflow.com/questions/32173320/php-rename-all-files-to) -low-case-in-a-directory-recursively) – Nic3500
すぐにコードをアップロードしないと申し訳ありません。それはすでに午前2時、私のGFは私に叫んでいた。これを行う方法を見つけるために一日中過ごした。 – feratechinc