2012-05-24 2 views
1

opencart 이미지 관리자를 사용하면 이미지 파일 이름에서 공백과 안전하지 않은 문자를 자동으로 제거하도록 업로드를 어떻게 설정할 수 있습니까?Opencart image upload 파일 이름을 안전하게합니다.

Filemanager.php

$filename = basename(html_entity_decode($this->request->files['image']['name'], ENT_QUOTES, 'UTF-8')); 

답변

1

가장 좋은 방법은 다시, 문자, 숫자, 밑줄 슬래시와 등을 수 그

$filename = preg_replace('~[^\w\./\\\\]+~', '', $filename); 

같은 간단한 preg_replace이다를 사용하는 것입니다. 파일 이름 만 빼고 다른 것을 제거하십시오.

+0

html_entity_decode 내부 또는 외부로 이동해야합니까? –

+1

파일을 업로드 할 때 html 엔티티 디코드가 필요하지 않습니다. –

+0

@JayGilford 다시 Opencart에 대한 지식을 얻고 나에게 깊은 인상을 남깁니다. OC Commerce Sphere Community의 자산입니다. 리핑. – TheBlackBenzKid

0

반드시 htmlspecialchars 다른 <> & ' "아무것도없는 안전하지 않은 문자에 대해 수행 할 필요가 정확히 않습니다.

 // for removing unsafe characters 
     $text = htmlspecialchars($text); 

// 제거 공백

정규 표현식 :

 preg_replace('/()+/', ' ', $string); 

     //If you also want to remove every multi-white characters, you can use \s (\s is white characters) 

     preg_replace('/(\s)+/', ' ', $string);