업로드하는 동안 이미지에 슬러그 이름을 넣으려고합니다. str_replace
으로 테스트했지만 작동하지 않습니다.이미지 POST PHP 슬러그
$_FILES['imgProfile']['name'] = str_replace("í", "i", $_FILES['imgProfile']['name']);
다음과 같이 반환합니다 : i?magen.png
이미지를 업로드하지 않습니다.
이 기능을 시도했지만 작동하지만 파일 확장명을 제거합니다.
function slugify($text)
{
// replace non letter or digits by -
$text = preg_replace('~[^\pL\d]+~u', '-', $text);
// transliterate
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
// remove unwanted characters
$text = preg_replace('~[^-\w]+~', '', $text);
// trim
$text = trim($text, '-');
// remove duplicate -
$text = preg_replace('~-+~', '-', $text);
// lowercase
$text = strtolower($text);
if (empty($text)) {
return 'n-a';
}
return $text;
}
는 난 단지 파일 이름 인 경우 a,e,i,o,u
와 á,é,í,ó,ú
같은 -
및 문자 blank spaces
를 제거해야합니다 "prueba para Guardar ímagen ñueva.png"
가되어야합니다 "prueba-para-guardar-imagen-nueva.png"
감사합니다! 원하는 행동에 대한
를나요? –
예, 작동하지 않습니다. –