Skip to content

Instantly share code, notes, and snippets.

@s9011514
Created November 25, 2015 09:34
Show Gist options
  • Save s9011514/0770f0ed637b0eb85869 to your computer and use it in GitHub Desktop.
Save s9011514/0770f0ed637b0eb85869 to your computer and use it in GitHub Desktop.
<?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