ITmembers.net 아카이브 · 2002–2009

질문과 답변

또 질문이요.

아래 문장에 올렸던 것들에서

        $upfile = "inputname".$num ;

이렇게 지우니까 되네요

그런데 또 애러가 생겨요

----------------
Warning: copy(inputname1): failed to open stream: No such file or directory in D:\web\index\t\multiupload_ok.php on line 37

Warning: copy(inputname2): failed to open stream: No such file or directory in D:\web\index\t\multiupload_ok.php on line 37

Warning: copy(inputname3): failed to open stream: No such file or directory in D:\web\index\t\multiupload_ok.php on line 37
---------------------------------
multiupload..php 소스

<html>

<head>

   <title>복수 개의 파일 업로드 기능</title>

   <meta http-equiv="Content-Type" content="text/html; charset=euc-kr">

<style type="text/css">

   BODY, TD, INPUT {font-family:굴림;font-size:9pt;color:#000000;}

   </style>

</head>

<body>

<form method="POST" ENCTYPE="multipart/form-data" action="multiupload_ok.php">

<table width="500" border="0" align="center" bgcolor="dddddd">

        <tr>

                <td width="600" colspan="2" align="center"><b>여러 개의 파일 업로드 기능</b></td>

        </tr>



<?

// 업로드 파일 갯수 지정($num) : 여기서는 3개로 지정함

for ($num = 1 ; $num <= 3 ; $num++) {

        $selectfile = "inputname".$num; // input 태그의 name 속성 값을 inputname1, inputname2, inputname3으로 설정하기 위함

?>

        <tr>

                <td width="100" align="center">파일명 <? echo "$num"; ?></td>

                <td width="500"> <input type="file" name="<? echo "$selectfile"; ?>" size="25">(파일의 용량 제한 : 20M)</td>

        </tr>

<?

}

?>



        <tr>

                <td align="center" colspan="2">

                        <input type="submit" value="전송"> <input type="reset" value="취소">

                </td>

        </tr>

</table>

</form>

</body>

</html>

---------------------------
multiupload_ok.php 소스

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr" />
<style type="text/css">

   BODY, TD, INPUT {font-family:굴림;font-size:9pt;color:#000000;}

</style>

</head>

<body>
<?

$target_dir = "up";  // 업로드한 파일이 저장될 디렉토리. 서버에 up 이라는 디렉토리가 있어야 한다.

$uploaded_yn = "N"; // 기본값으로 N 설정. 파일이 하나라도 업로드될 경우 나중에 "Y"로 바꾸게 됨.

for ($num = 1 ; $num <= 3 ; $num++) { // 업로드한 파일이 최대 3개일 경우

        $upfile = "inputname".$num ; // ${selectfile1} → $selectfile1 과 동일. 임시 파일명

        $upfile_name = "inputname".$num."_name" ; // INPUT 태그의 이름 뒤에 "_name"을 붙이면 실제 파일 이름의 변수가 된다. PHP에서 자동 생성되는 변수명.

        $upfile_size = "inputname".$num."_size" ; // 파일 사이즈

        $upfile_type = "inputname".$num."_type" ; // 파일 타입

        if(!strcmp($upfile,"none")) {   // $upfile이 "none"이면 0, 아니면 1이 됨. 따라서 업로드되지 않았을 경우에 strcmp 결과는 0이 되고, !strcmp 이므로 if 조건문은 1이 되어 참이 됨. 으~ 복잡해라. 한마디로 파일이 업로드되지 않았을 경우 아래 코드를 실행하라는 뜻.

                continue; // 아래 코드를 실행하지 말고 for 문으로 다시 돌아가라는 뜻.

        } else { // 파일이 업로드되었다면...

            $target = $target_dir . "/" . $upfile_name;

            if(!copy($upfile,$target)) {   // false일 경우

               continue;

                }

                $uploaded_yn = "Y";

?>



    <table width="500" border="0" cellspacing="1" cellpadding="2" align="center">

    <tr>

       <td colspan="2" align="center" bgColor="#CCCCCC" width="100%"><font size=2><b>>> 업로드 성공 <<</b></font></td>

    </tr>

    <tr>

       <td align="left" bgColor="#EEEEEE" width="120"><font size=2>파일명</font></td>

       <td bgColor="#EEEEEE"><font size=2><?echo("$upfile_name")?></font></td>

    </tr>

    <tr>

       <td align="left" bgColor="#EEEEEE" width="120"><font size=2>임시 저장 파일명</font></td>

       <td bgColor="#EEEEEE"><font size=2><?echo("$upfile")?></font></td>

    </tr>

    <tr>

       <td align="left" bgColor="#EEEEEE" width="120"><font size=2>파일 크기(Bytes)</font></td>

       <td bgColor="#EEEEEE"><font size=2><?echo("$upfile_size")?> Bytes</font></td>

    </tr>

    <tr>

       <td align="left" bgColor="#EEEEEE" width="120"><font size=2>파일의 MIME Type</font></td>

       <td bgColor="#EEEEEE"><font size=2><?echo("$upfile_type")?></font></td>

    </tr>

    </table>



<?

} // 22행의 else 닫기



if ($uploaded_yn == "N") {

?>

        <table width="500" border="0" cellspacing="1" cellpadding="2" align="center" bgcolor="#FFCCFF">

    <tr>

       <td width="100%" align="center" bgColor="#CCCCCC"><font size=2><b>업로드 실패!!!</b></font></td>

    </tr>

    </table>

</body>

</html>



<?

} // 55행의 if 문 닫기

} // 15행의 for 문 닫기

?>

댓글 1