상세 컨텐츠

본문 제목

blueimp jQuery Fileupload 파일업로드 파일명 중복시에 덮어씌우기

IT공부방/jQuery, ajax, java

by 동해둘리 2016. 8. 30. 19:44

본문

반응형

blueimp jQuery Fileupload Plugin 사용시, 파일명이 중복될때 덮어씌우기



https://github.com/blueimp/jQuery-File-Upload  에서 구할 수 있는 

jQuery blueimp Fileupload Plugin 을 사용하면,  파일업로드를 아주 쉽게 구현할 수 있습니다.


기본적으로 설치하여 사용하는 방법은 얼마전에 올린 아래 포스팅을 참고하시기 바랍니다.

http://doolyit.tistory.com/38




이번 포스팅에서 확인할 부분은, 업로드하는 파일명이 중복되는 경우에 대한 처리입니다.


플러그인 설치후에 upload handler 가 설치되어 있는 server 폴더를 보면 UploadHandler.php 가 있는데요 (PHP 의 경우)

그 파일을 보면 아래와 같이 되어 있습니다.


protected function get_file_name($file_path, $name, $size, $type, $error,           

        $index, $content_range) {                                                                

        $name = $this->trim_file_name($file_path, $name, $size, $type, $error,     

            $index, $content_range);                                                             


return $this->get_unique_filename(                                             

            $file_path,                                                                         

            $this->fix_file_extension($file_path, $name, $size, $type, $error,    

                $index, $content_range),                                                  

            $size,                   

            $type,                  

            $error,                 

            $index,                

            $content_range     

        );                            

}                                    


이를 그대로 사용하게되면 파일이 중복되는 경우 이름을 새로 만들어서 겹치지 않게 업로드 하게 되는데요
예를들어 test.jpg 파일을 업로드 한 후에, 중복으로 업로드 하게되면 test_(1).jpg 등과 같이 파일명을 변경하여 업로드 하게 됩니다.

이를 막고, 그냥 덮어쓰기를 원한다면, 위 코드를 아래와 같이 변경하면 됩니다. 


return $this -> trim_file_name($file_path, $name, $size, $type, $error, $index, $content_range);

반응형

관련글 더보기

댓글 영역