33use Illuminate \Support \Facades \Storage ;
44use Aws \S3 \S3Client ;
55use Aws \S3 \PostObjectV4 ;
6+ use Illuminate \Support \Str ;
67
78if (!function_exists ('s3Endpoint ' )) {
89 /**
@@ -60,13 +61,11 @@ function bytesToHuman($bytes)
6061 /**
6162 * @param string $str
6263 * @return bool|string
64+ * @deprecated Use Str::ascii instead
6365 */
6466 function replaceAccents ($ str )
6567 {
66- if (function_exists ('mb_convert_encoding ' )) {
67- return mb_convert_encoding ($ str , 'ASCII ' , 'UTF-8 ' );
68- }
69- return iconv ('UTF-8 ' , 'ASCII//TRANSLIT ' , $ str );
68+ return Str::ascii ($ str );
7069 }
7170}
7271
@@ -77,7 +76,7 @@ function replaceAccents($str)
7776 */
7877 function sanitizeFilename ($ filename )
7978 {
80- $ sanitizedFilename = replaceAccents ($ filename );
79+ $ sanitizedFilename = Str:: ascii ($ filename );
8180
8281 $ invalid = array (
8382 ' ' => '- ' ,
@@ -87,8 +86,8 @@ function sanitizeFilename($filename)
8786
8887 $ sanitizedFilename = str_replace (array_keys ($ invalid ), array_values ($ invalid ), $ sanitizedFilename );
8988
90- $ sanitizedFilename = preg_replace ('#[^A-Za-z0-9-\ . ]# ' , '' , $ sanitizedFilename ); // Remove all non-alphanumeric except .
91- $ sanitizedFilename = preg_replace ('#\.(?=.*\.)# ' , '' , $ sanitizedFilename ); // Remove all but last .
89+ $ sanitizedFilename = preg_replace ('#[^A-Za-z0-9-. ]# ' , '' , $ sanitizedFilename ); // Remove all non-alphanumeric except .
90+ $ sanitizedFilename = preg_replace ('#\.(?=.*\.)# ' , '- ' , $ sanitizedFilename ); // Remove all but last .
9291 $ sanitizedFilename = preg_replace ('#-+# ' , '- ' , $ sanitizedFilename ); // Replace any more than one - in a row
9392 $ sanitizedFilename = str_replace ('-. ' , '. ' , $ sanitizedFilename ); // Remove last - if at the end
9493 $ sanitizedFilename = strtolower ($ sanitizedFilename ); // Lowercase
0 commit comments