nugawiki

./categories/back-end

PHP 파일 업로드

업데이트 2026-07-21 조회수

업로드 폼 (HTML)

<form enctype="multipart/form-data" action="1.php" method="POST">
  <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
  <input name="userfile" type="file" />
  <input type="submit" value="upload" />
</form>

업로드 처리 (PHP)

<?php
ini_set("display_errors", "1");
$uploaddir = '/path/to/upload/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    echo "파일이 유효하고, 성공적으로 업로드 되었습니다.\n";
} else {
    print "파일 업로드 공격의 가능성이 있습니다!\n";
}
print_r($_FILES);   // 디버깅용
?>

./comments