我的一些用戶將附加名稱包含特殊字符的文件,這些文件在下載和上傳,單引號,空格等時對實用程序有問題。這看起來應該是一個簡單的問題來解決,但因爲我是一個「綠色」編碼時,我可以使用一些幫助。jQuery文件上傳 - 具有特殊字符的blueimp文件名
我試着修改'UploadHandler.php'函數來操作文件名沒有成功。我不知道如果我需要在表格上或上傳的輸入電平來解決它......
我最後的嘗試是在trim_file_name()函數:
protected function trim_file_name($name,
$type = null, $index = null, $content_range = null) {
// Remove path information and dots around the filename, to prevent uploading
// into different directories or replacing hidden system files.
// Also remove control characters and spaces (\x00..\x20) around the filename:
$name = trim(basename(stripslashes($name)), ".\x00..\x20");
// Use a timestamp for empty filenames:
if (!$name) {
$name = str_replace('.', '-', microtime(true));
$name = preg_replace('/[^A-Za-z0-9\-]/', '', $name); <==== my attempt
}
// Add missing file extension for known image types:
if (strpos($name, '.') === false &&
preg_match('/^image\/(gif|jpe?g|png)/', $type, $matches)) {
$name .= '.'.$matches[1];
}
return $name;
}
我真的可以使用一些幫助。我真的很沮喪。
感謝,
in wordpress,'sanitize_file_name()'很好。從wordpress/wp-includes/formatting.php複製這個函數並使用它 –