파일업로드 예제

tips 2010. 1. 5. 20:54 |
--php--
upload.html

<html>
<body>
<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>

</body>
</html>



upload_file.php
<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }
?>


--asp-- 컴포넌트의 설치가 필요하다
upload.html
 <form METHOD ="POST" action="upload_file.asp" name="form" enctype="multipart/form-data">
<input type="file" name="ufile"  size="20"><input type=submit>
</form>
</table>

upload_file.asp
<% set up = Server.CreateObject("SiteGalaxyUpload.Form")
set fs = server.CreateObject("Scripting.FileSystemObject")
fn = "c:\carmel\board\upload\" & fs.GetFileName(up("ufile").FilePath)
up("ufile").SaveAs(fn)
%>
<html>
<body>
업로드
</body>
</html>
<% set fs = Nothing
set up = Nothing %>

'tips' 카테고리의 다른 글

WebAPP별 파라미터 전송방식  (0) 2010.02.01
윈도우 확장자 한꺼번에 바꾸기  (0) 2010.01.25
OS Command Injection 환경예제  (0) 2010.01.04
DEP 해제  (0) 2009.12.29
Apache DefaultCharset  (0) 2009.12.04
Posted by applicationlayer
: