회원로그인
PHP 간단한 파일 업로드(upload) 예제
15년 전
php를 이용해서 파일 한개를 업로드 하는 간단한 예제입니다. 예제가 너무 간단하므로 부연설명은 피하도록 하겠습니다. 단 업로드를 담당하는 uptest.html과 uptest_end.php 가 있는 디렉토리에 upload란 폴더를 만들어 주셔야 합니다.
그리고 퍼미션은 707로 주시면 됩니다.
보내는 파일(uptest.html) <html>
<head>
<title>간단업로드</title>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
</head>
<body>
<table width="550" border="0" cellspacing="0" cellpadding="0">
<tr>
<form name="upform" method="POST" enctype="multipart/form-data" action="uptest_end.php">
<td width="78" align="center"> 파일</td>
<td width="390"> <input type="file" name="upfile" size="38"></td>
<td width="82"> <input type="submit" name="Submit" value="전송"></td>
</form>
</tr>
</table>
</body>
</html>
업로드 파일을 처리하는 파일(uptest_end.php) <?php
$upfile_ext=substr(strrchr($upfile_name,"."),1); //파일확장자를 구한다
if(eregi("php|cgi|exe|jsp|asp|aspx", $upfile_ext)){ //파일확장자를 체크하여 업로드를 제한한다
echo"<script type='text/javascript'>alert('파일 업로드가 제한된 파일입니다.');history.go(-1);</script>";
exit;
}
echo"파일명:".$upfile_name."<br>";
echo"임시파일명:".$upfile."<br>";
echo"파일크기:".$upfile_size."<br>";
echo"파일타입:".$upfile_type."<br>";
echo"파일확장자:".$upfile_ext."<br>";
if(copy($upfile,"upload/".$upfile_name)){
echo"<strong>업로드성공</strong>";
} else {
echo"<strong>업로드실패</strong>";
}
?>
추천 : 614
추천
목록