CodeIgniter 한국사용자포럼 BETA
빠르고, 유연한 PHP Framework!

TIP게시판


파일업로드시 타입 에러      
웅파 5 1,695 0 0 2010-05-13 15:39:52
 Upload 라이브러리 이용하여 업로드시 분명히 맞는 파일타입임에도 업로드가 되지 않을때가 있습니다.

$allow_type = array('jpg', 'zip'); //이렇게 이미지가 먼저 나올 경우 에러가 납니다.

원래 core를 건드리지 않는다가 철칙이지만 버그인 경우는 어쩔 수 없이 손을 댑니다.

system/libraries/Upload.php 파일의 다음함수를 바꿔주시면 됩니다.

/**
	 * Verify that the filetype is allowed
	 *
	 * @access	public
	 * @return	bool
	 */
	function is_allowed_filetype()
    {
        if (count($this->allowed_types) == 0 OR ! is_array($this->allowed_types))
        {
            $this->set_error('upload_no_file_types');
            return FALSE;
        }

        //kofic - hacking - start
        $ext_found = 0;
        $ext = $this->file_ext;
        $ext = str_replace(".","",$ext);
        //kofic - hacking - end


        $image_types = array('gif', 'jpg', 'jpeg', 'png', 'jpe');

        foreach ($this->allowed_types as $val)
        {
            //kofic - hacking - start
            if ( strtolower($val) == strtolower($ext) ){$ext_found = 1;}
            //kofic - hacking - end

            $mime = $this->mimes_types(strtolower($val));

            //kofic - hacking - start
            // Images get some additional checks
            //kofic - commenting original code - start
            //if (in_array($val, $image_types))
            //kofic - commenting original code - end
            if (in_array($ext, $image_types))
            //kofic - hacking - end
            {
                if (getimagesize($this->file_temp) === FALSE)
                {
                    return FALSE;
                }
            }

            if (is_array($mime))
            {
                if (in_array($this->file_type, $mime, TRUE))
                {
                    return TRUE;
                }
            }
            else
            {
                if ($mime == $this->file_type)
                {
                    return TRUE;
                }
            }
        }

        //kofic - hacking - start
        if ( $ext_found ){ return TRUE; }
        //kofic - hacking - end

        return FALSE;
    }
 
  목록  

KangMin 2010-05-13 16:01:13
  

아.. 그렇군요.. 아직 파일 업로드까진 안해봐서리... 캄사합니다...2.0에서는 해결될라낭...

kirrie 2010-05-13 16:10:03
  
ㅎㅎㅎ 저도 며칠전에 이거 발견하고 수정했는데. ㅋㅋ
이 업로드 클래스가 웃긴게 이미지가 아니어도 굳이 이미지 파일인지 아닌지 검사하려고 그러던 거였더라구요.

케이든 2010-05-13 16:12:31
  
좋스빈다!!

코어를 안건드리고

확장해서 메쏘드를 오버라이딩 하면 되지 않을까요?
kirrie 2010-05-13 16:18:58
  
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Upload extends CI_Upload {

	function MY_Upload($props = array())
	{
		parent::CI_Upload($props);
	}
	
	/**
	 * Verify that the filetype is allowed
	 *
	 * @access	public
	 * @return	bool
	 */	
	function is_allowed_filetype()
	{
		if (count($this->allowed_types) == 0 OR ! is_array($this->allowed_types))
		{
			$this->set_error('upload_no_file_types');
			return FALSE;
		}

		$image_types = array('gif', 'jpg', 'jpeg', 'png', 'jpe');

		foreach ($this->allowed_types as $val)
		{
			$mime = $this->mimes_types(strtolower($val));

			// Images get some additional checks
			if (in_array($val, $image_types) && $this->is_image() === TRUE)
			{
				if (getimagesize($this->file_temp) === FALSE)
				{
					return FALSE;
				}
			}

			if (is_array($mime))
			{
				if (in_array($this->file_type, $mime, TRUE))
				{
					return TRUE;
				}
			}
			else
			{
				if ($mime == $this->file_type)
				{
					return TRUE;
				}	
			}		
		}
		
		return FALSE;
	}
	
	// --------------------------------------------------------------------
}
/* End of file */
전 이렇게 수정해서 확장했습니다.
웅파 2010-05-13 16:29:00
  
키리에/ 땡유. ^^

번호 제   목 글쓴이 날짜 조회 추천수
829 HMVC 5.4 & Template_ 타로구조 만들기 [1] 타로 2012-02-02 100 0
824 CI lang팩 -> Javascript lang팩 [4] KangMin 2012-01-25 184 0
823 anchor_popup 헬퍼 화면 정 가운데 띄우기.. [0] DJ구스 2012-01-17 149 0
822 [자바스크립트] 창을 화면 정중앙에 위치하게 계산하기 [0] 웅파 2012-01-11 182 0
815 hook에서 선언한 변수를 컨트롤러에서 사용하기 [2] 웅파 2011-12-27 368 0
812 mysql 부분적인 에러 핸들링 처리 [2] EziX 2011-12-20 390 0
811 컨트롤러 외부에서의 종료방법 [1] EziX 2011-12-20 302 0
809 icodekore sms 모듈 쓰는 분들 참고하세요.. [0] namGoos 2011-12-09 514 0
803 Upgrading from 2.0.3 to 2.1.0 [5] namGoos 2011-12-06 493 0
794 .svn 폴더 삭제 하기 [7] 불의회상 2011-11-30 452 1
792 [1원] 윈도우서버+mssql 에서 CLI(Comm.. [2] 터프키드 2011-11-29 458 0
786 Form_validation 라이브러리 less_t.. [2] EziX 2011-11-17 460 0
780 1원팁. 저의 Template_ 이용방법입니다. [2] namGoos 2011-10-31 995 0
773 MYSQL 자동으로 시간 설정 [5] 불의회상 2011-10-26 659 0
767 모바일 웹사이트 개발시 참조하시면 좋을 것 같네요~ [7] 탱크 2011-10-20 781 1
764 EUC-KR 판정 방법 [3] 불의회상 2011-10-18 727 0
758 eclipse Autocomplete 업데이트 버전. [4] EziX 2011-10-14 937 0
751 글로벌 사이트를 위한 시간(GMT) 적용 [8] 웅파 2011-10-12 518 0
744 포토바다 개발 내규 문서 공개합니다. [7] namGoos 2011-10-10 846 1
735 jquery cheat 1.0 ~ 1.6 [6] 웅파 2011-10-06 759 0