정보실

웹학교

정보실

php Processing an uploaded file

본문

<?php

$maxsize=28480; 

if (!$HTTP_POST_VARS['submit']) {

    $error=" ";

}

if (!is_uploaded_file($HTTP_POST_FILES['upload_file']['tmp_name']) AND !isset($error)) {

    $error = "<b>You must upload a file!</b><br /><br />";

    unlink($HTTP_POST_FILES['upload_file']['tmp_name']);

}

if ($HTTP_POST_FILES['upload_file']['size'] > $maxsize AND !isset($error)) {

    $error = "<b>Error, file must be less than $maxsize bytes.</b><br /><br />";

    unlink($HTTP_POST_FILES['upload_file']['tmp_name']);

}

if (!isset($error)) {

    move_uploaded_file($HTTP_POST_FILES['upload_file']['tmp_name'],

                       "uploads/".$HTTP_POST_FILES['upload_file']['name']);

    print "Thank you for your upload.";

    exit;

}

else

{

    echo ("$error");

}

?>

 

<html>

<head></head>

<body>

<form action="<?php echo(htmlspecialchars($_SERVER['PHP_SELF']))?>"

method="post" enctype="multipart/form-data">

    Choose a file to upload:<br />

    <input type="file" name="upload_file" size="80">

    <br />

    <input type="submit" name="submit" value="submit">

</form>

</body>

</html> 

  • 트위터로 보내기
  • 페이스북으로 보내기
  • 구글플러스로 보내기
  • 카카오톡으로 보내기

페이지 정보

조회 172회 ]  작성일15-06-10 08:25
php

웹학교