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 디렉토리에 파일이 업로드가 된다.