我的问题的续集:Addslashes displays as forward slashes in php,
我想从我服务器上的文件的文件名中删除斜杠。在文件上传期间添加了斜杠(magic_quotes)。
请问我怎么能这样做?感谢
答案 0 :(得分:2)
答案 1 :(得分:2)
你走了:
<?php
$path = '/path/to/files/dir/';
$file_types = 'txt,doc,pdf';
foreach (glob($path.'*.{'.$file_types.'}', GLOB_BRACE) as $filename){
if(rename($filename , stripslashes($filename))){
echo 'Renamed file from '.$filename.' to '.stripslashes($filename).'<br />';
} else{
echo 'Failed to rename file from '.$filename.' to '.stripslashes($filename).'<br />';
}
}
?>
更改文件路径和逗号分隔的文件类型列表。
$dir='cv';
if(is_dir($dir)){
if ($dh = opendir($dir)) {
while (false !== ($file = readdir($dh))) {
if ($file != "." && $file != "..") {
$file2 = $dir."/".$file; $newfile=$dir."/".stripslashes(urldecode($file));
if(rename($file2, $newfile)){
echo "renamed from $file2 to $newfile <br>";
} else{
echo "error renaming from $file2 to $newfile <br>";
}
}
}
closedir($dh);
}
}