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

php 文件上传实现

时间:2015-03-11 09:17:37      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:

upload.php

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<form action="doAction.php" method="post" enctype="multipart/form-data">
请选择您要上传的文件:
<input type=‘file‘ name=‘myFile‘ />
<br />
<input type="submit" value="upload" />
</form>


</body>
</html>

doAction.php

<?php
//print_r($_FILES);
$filename=$_FILES[‘myFile‘][‘name‘];
$type=$_FILES[‘myFile‘][‘type‘];
$tmp_name=$_FILES[‘myFile‘][‘tmp_name‘];
$size=$_FILES[‘myFile‘][‘size‘];
$error=$_FILES[‘myFile‘][‘error‘];

//remove file
//move_uploaded_file($tmp_name,$destination);
//move_uploaded_file($tmp_name,"./".$filename);
//copy($src,$dst)

if($error == UPLOAD_ERR_OK)
{
  if(move_uploaded_file($tmp_name,"./".$filename))
  {
    echo ‘upload success‘;
  }
  else
  {
    echo "upload failed";
  }
}
else
{
  switch($error)
  {
    case 1:
      echo "error :1 --超过了php.ini文件中upload_max_filesize的值"

      break;
    case 2:
      echo "error :2 --上传文件的大小超过了表单MAX_FILE_SIZE的值";
      break;
    case 3:
      echo "error :3 --文件只有部分上传";
      break;
    case 4:
      echo "error :4 --没有文件上传";
      break;
    case 6:
      echo "error :6 --找不到临时文件夹";
      break;
    case 7:
      echo "error :7 --写入失败";
      break;
    case 8:
      echo "error :8 --上传的文件被php扩展程序中断";
      break;
   }
}
?>

php 文件上传实现

标签:

原文地址:http://www.cnblogs.com/saryli/p/4328953.html

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