Created
November 25, 2015 09:34
-
-
Save s9011514/0770f0ed637b0eb85869 to your computer and use it in GitHub Desktop.
This file contains 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
<?php | |
/** | |
功能:檔案避免中文檔名 | |
**/ | |
function achang_chang_filename_to_date($filename) { | |
$info = pathinfo($filename); | |
$ext = empty($info['extension']) ? '' : '.' . $info['extension']; | |
$name = basename($filename, $ext); | |
if(!is_numeric($name)){ | |
$time = date_i18n( 'Y-m-d-His-', false,false ); | |
$new_filename = $time .mt_rand(1,100); | |
}else{ | |
$new_filename = $name; | |
} | |
return $new_filename . $ext; | |
} | |
add_filter('sanitize_file_name', 'achang_chang_filename_to_date', 10); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment