티스토리 뷰

php

php 파일 업로드

xemaker 2017. 12. 11. 21:48

<form action="./itemexcelupdate.php" method="post" enctype="multipart/form-data"> 

<input type="file"  name="filepath" id="filepath"/></td><td>

<input type="submit" name="SubmitButton"/>

 </form>


위와 같이 폼파일을 만들고


itemexcelupdate.php 파일을 만들고 아래와 같이 작성한다.

<?

if(isset($_POST['SubmitButton'])){

$target_dir = 'uploads/';

if( !is_dir($target_dir)){

mkdir($target_dir);

}

$target_file = $target_dir . basename($_FILES["filepath"]["name"]);

move_uploaded_file($_FILES["filepath"]["tmp_name"], $target_file);

}

?>


그럼 uploads 디렉토리에 파일이 업로드가 된다.

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/08   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함