Created
October 12, 2013 10:25
-
-
Save jeonghwan-kim/6948408 to your computer and use it in GitHub Desktop.
php 파일 업로드
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| if(isset($_POST['submit'])) { | |
| $save_dir = "./"; | |
| //파일이 HTTP POST 방식을 통해 정상적으로 업로드되었는지 확인한다. | |
| if(is_uploaded_file($_FILES["upload_file"]["tmp_name"])){ | |
| echo "업로드한 파일명 : " . $_FILES["upload_file"]["name"]; | |
| //파일을 저장할 디렉토리 및 파일명 | |
| $dest = $save_dir . $_FILES["upload_file"]["name"]; | |
| //파일을 지정한 디렉토리에 저장 | |
| if(move_uploaded_file($_FILES["upload_file"]["tmp_name"], $dest)) | |
| echo "success"; | |
| else | |
| die("fail2"); | |
| } else { | |
| echo "fail1"; | |
| } | |
| } | |
| ?> | |
| <form enctype="multipart/form-data" method="post" | |
| action="<?php echo $_SERVER['PHP_SELF']; ?>"> | |
| <input type="file" name="upload_file" /><br /> | |
| <input type="submit" value="upload" name="submit"/> | |
| </form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$_SERVER["REQUEST_METHOD"] == "POST" 사용하세요
action 부분은 안쓰셔도 됩니다