Skip to content

file 태그를 사용해서 배열 형식의 파일 업로드시 에러 #2110

@wonsuc

Description

@wonsuc

배열 형식의 값들을 전송하는 모듈을 제작하고 있기 때문에 폼 name에 "[]"를 붙혀서 값들을 전송하고 있었습니다. 오늘 "모바일 이미지"라는 새로운 배열 형식의 파일 업로드를 추가하였는데 의도와 다른 결과값이 나옵니다.

아래는 aaa[]에만 파일을 첨부한 뒤 업로드 해본 결과입니다.

[upload.html]

<form action="./" method="post" enctype="multipart/form-data">
	<input type="hidden" name="act" value="procMainvisualInsertAll">
	<label>PC 이미지</label><input type="file" name="aaa[]" title="첨부">
	<label>모바일 이미지</label><input type="file" name="bbb[]" title="첨부">
	<button type="submit">등록</button>
</form>

[mainvisual.controller.php]

function procMainvisualInsertAll() {
	$args = Context::getRequestVars();
	debugPrint("initial_args:");
	debugPrint($args);
	...
}

[debug result]

[2017-06-14 00:43:44 modules/mainvisual/mainvisual.controller.php:48] mainvisualController->procMainvisualInsertAll() - mem(4.45MB)
================================================================================
DEBUG : stdClass Object
        (
            [error_return_url] => /xe/index.php?module=admin&act=dispMainvisualAdminIndex
            [act] => procMainvisualInsertAll
            [aaa] => Array
                (
                    [0] => Array
                        (
                            [name] => 4efdd2f969559e8b1c92e99f32ded48e145812.jpg
                            [type] => image/jpeg
                            [tmp_name] => /tmp/phpCWHfN7
                            [error] => 0
                            [size] => 409075
                        )
                )
            [bbb] => Array
                (
                    [0] => Array
                        (
                            [name] => 4efdd2f969559e8b1c92e99f32ded48e145812.jpg
                            [type] => image/jpeg
                            [tmp_name] => /tmp/phpCWHfN7
                            [error] => 0
                            [size] => 409075
                        )
                )
        )
        - /home/hosting_users/zoopiter5/www/xe/modules/mainvisual/mainvisual.controller.php : 48
        - /home/hosting_users/zoopiter5/www/xe/classes/module/ModuleObject.class.php : 443
        - /home/hosting_users/zoopiter5/www/xe/classes/module/ModuleHandler.class.php : 844
        - /home/hosting_users/zoopiter5/www/xe/index.php : 59

보시다시피 bbb[]에도 파일이 포함 되어있는 것을 볼 수 있습니다.
아래는 정상적인 vanilla php에 파일을 업로드 해봤습니다.

[file.php]

<?
	print_r($_FILES);
?>

[debug result]

Array
(
    [aaa] => Array
        (
            [name] => Array
                (
                    [0] => 15.png
                )

            [type] => Array
                (
                    [0] => image/png
                )

            [tmp_name] => Array
                (
                    [0] => /tmp/phpbb8jrF
                )

            [error] => Array
                (
                    [0] => 0
                )

            [size] => Array
                (
                    [0] => 479377
                )

        )

    [bbb] => Array
        (
            [name] => Array
                (
                    [0] => 
                )

            [type] => Array
                (
                    [0] => 
                )

            [tmp_name] => Array
                (
                    [0] => 
                )

            [error] => Array
                (
                    [0] => 4
                )

            [size] => Array
                (
                    [0] => 0
                )

        )

)

의도한 대로 결과값이 나오는 것을 볼 수 있습니다.

XE를 통해서 배열 방식의 업로드를 할 때 가장 처음에 삽입된 file 태그의 값이 그 이후의 변수에도 삽입되어 버립니다. 예를 들어서 aaa[], bbb[]에 각각 다른 파일을 첨부하였을 경우 aaa[]에는 1개의 파일, bbb[]에는 aaa[]에서 첨부한 파일 및 bbb[]에서 첨부한 파일 이렇게 2개의 파일이 존재합니다.

테스트한 XE 버전은 가장 최신 버전입니다. 검토 부탁드립니다.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions