나만 알 수 없어서 만든 블로그

$_FILES 이것은 무엇인가...? 본문

PHP/고급

$_FILES 이것은 무엇인가...?

코딩낙타 2020. 7. 17. 00:34

move_uploaded_file()로 POST한 $_FILES의 값이 궁금해졌다. 어떻게 구성되었길래 나를 그렇게 고통스럽게 해? ㅜㅜㅜㅜㅜ

그럼 뭐다? 검색이다.

 

 

구글링으로 알아낸 것은...

 

$_FILES 또는$HTTP_POST_FILES [deprecated]

$ HTTP_POST_FILES 에는 동일한 초기 정보가 포함되어 있지만 superglobal 은 아닙니다. ( $ HTTP_POST_FILES 와 $ _FILES 는 다른 변수이며 PHP는 그와 같이 변수를 처리합니다)

 

설명을 번역하면 저 말인데 결론은 글로벌 변수 (전역변수) 는 $ _FILES이며, $ HTTP_POST_FILES는 글로벌 변수(전역변수)가 아님.

 

$ _FILES : 내가 부르면 어디든 오는 착한 대기조 or 단축키로 지정된 연락처

$ HTTP_POST_FILES : 연락처를 저장하고 불러야 하는 친구

 

↓ 구글로 번역 후 다시 내가 이해한 내용으로 주석을 달았다. 100% 확신하지 말 것.

 

Array
(
    [file1] => Array
        (
            [name] => MyFile.txt
            //(comes from the browser, so treat as tainted)
            // 브라우저에서 업로드된 파일은 언제나 의심해야 한다. 파일 처리를 할 때 꼭 확인할 것
            [type] => text/plain 
            //(not sure where it gets this from - assume the browser, so treat as tainted)
            // 어디에서 업로드된 것인지 불확실하다. 위험한 요소이므로 항상 의심한다.
            [tmp_name] => /tmp/php/php1h4j1o
            //(could be anywhere on your system, depending on your config settings, but the user has no control, so this isn't tainted)
            // 설정에 따라서 시스템 어디에서나 존재할 수 있다. 그러나 사용자는 접근하기 어려운 곳이므로 안전하다.
            [error] => UPLOAD_ERR_OK  (= 0)
            [size] => 123
            //(the size in bytes)
            // 바이트 단위의 사이즈
        )

    [file2] => Array
        (
            [name] => MyFile.jpg
            [type] => image/jpeg
            [tmp_name] => /tmp/php/php6hst32
            [error] => UPLOAD_ERR_OK
            [size] => 98174
        )
)

 

양식에 배열을 사용하는 경우에는 $ _FILES의 배열 형식이 이렇게 나온다고 합니다.

ex) download[file1] download[file2]

 

※ 오류 변수를 불러올 때도 달라진다.

※  $ _Files [ 'download'] [ 'error'] [ 'file1']

 

Array
(
    [download] => Array
        (
            [name] => Array
                (
                    [file1] => MyFile.txt
                    [file2] => MyFile.jpg
                )

            [type] => Array
                (
                    [file1] => text/plain
                    [file2] => image/jpeg
                )

            [tmp_name] => Array
                (
                    [file1] => /tmp/php/php1h4j1o
                    [file2] => /tmp/php/php6hst32
                )

            [error] => Array
                (
                    [file1] => UPLOAD_ERR_OK
                    [file2] => UPLOAD_ERR_OK
                )

            [size] => Array
                (
                    [file1] => 123
                    [file2] => 98174
                )
        )
)

 

 

 

출처 中 dewi at dewimorgan dot com

 

https://www.php.net/manual/en/reserved.variables.files.php 

 

PHP: $_FILES - Manual

The format of this array is (assuming your form has two input type=file fields named "file1", "file2", etc):Array(    [file1] => Array        (            [name] => MyFile.txt (comes from the browser, so treat as tainted)            [type

www.php.net

 

 

'PHP > 고급' 카테고리의 다른 글

CI4 codeigniter4에 PHPEcxel 사용하기  (0) 2021.01.21
Mysqpl DB랑 연결하고 나온 결과를 어떻게 할까?  (0) 2020.08.26
move_uploaded_file()란?  (1) 2020.07.17