码迷,mamicode.com
首页 > Web开发 > 详细

php上传文件

时间:2015-06-06 20:43:37      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:

 upload_file.php

<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")))
//&& ($_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";
  }
?>

 index.html

<html>

<style> 
.btn{width:140px;height:36px;line-height:18px;font-size:18px;
background:url("button_bg.jpg") no-repeat left top;color:#FFF;padding-bottom:4px} 
</style> 

<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" class="btn"  name="submit" value="Submit"  onmouseover="this.style.backgroundPosition=‘left -36px‘"
 onmouseout="this.style.backgroundPosition=‘left top‘" />
</form>

</body>
</html>

button_bg.jpg

技术分享

 

php上传文件

标签:

原文地址:http://www.cnblogs.com/manhua/p/4557243.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!