사이트 내 전체검색
PHP
[php] $_FILES['uploadFile'] ['error'] 파일 업로드 시 에러 처리
로빈아빠
https://cmd.kr/php/286 URL이 복사되었습니다.

본문

$_FILES['uploadFile'] ['error'] 코드는 PHP 4.2.0에서 추가되었습니다.

0 : UPLOAD_ERR_OK, 성공
1 : UPLOAD_ERR_INT_SIZE, 업로드한 파일 크기가 PHP 'upload_max_filesize' 설정값보다 클 경우
2 : UPLOAD_ERR_FORM_SIZE, 업로드한 파일 크기가 HTML 폼에 명시한 MAX_FILE_SIZE 값보다 클 경우
3 : UPLOAD_ERR_PARTIAL, 파일중 일부만 전송된 경우
4 : UPLOAD_ERR_NO_FILE, 파일도 전송되지 않았을 경우

아래는 사용 방법 예시입니다.
먼저 파일을 업로드하는 폼 페이지입니다.

<html>
<head>
<title>File Upload Form</title>
</head>
<body>

<form action="getfile.php" method="post">
Type (or select) Filename: <input type="file" name="uploadFile">
<input type="hidden" name="MAX_FILE_SIZE" value="25000" />
<input type="submit" value="Upload File">
</form>

</body>
</html>

업로드한 파일을 처리하는 페이지입니다.

<html>
<head>
<title>Process Uploaded File</title>
</head>
<body>

<?php
if ( move_uploaded_file ($_FILES['uploadFile'] ['tmp_name'], "../uploads/{$_FILES['uploadFile'] ['name']}") )
 {  print '<p> The file has been successfully uploaded </p>';
       }
else
      {
        switch ($_FILES['uploadFile'] ['error'])
         {  case 1:
                   print '<p> The file is bigger than this PHP installation allows</p>';
                   break;
            case 2:
                   print '<p> The file is bigger than this form allows</p>';
                   break;
            case 3:
                   print '<p> Only part of the file was uploaded</p>';
                   break;
            case 4:
                   print '<p> No file was uploaded</p>';
                   break;
         }
       }
?>
</body>

댓글목록

등록된 댓글이 없습니다.

PHP
871 (5/18P)

Search

Copyright © Cmd 명령어 18.188.96.5