Skip to content

Instantly share code, notes, and snippets.

@jeonghwan-kim
Created October 12, 2013 10:25
Show Gist options
  • Select an option

  • Save jeonghwan-kim/6948408 to your computer and use it in GitHub Desktop.

Select an option

Save jeonghwan-kim/6948408 to your computer and use it in GitHub Desktop.
php 파일 업로드
<?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>
@maxswjeon
Copy link
Copy Markdown

$_SERVER["REQUEST_METHOD"] == "POST" 사용하세요
action 부분은 안쓰셔도 됩니다

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment