php实现web页面文件上传的代码

 

unfile.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml">

<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<TITLE>文件上传页面</TITLE>
</HEAD>
<BODY>
<FORM ACTION="upload.php" ENCTYPE="multipart/form-data" METHOD="POST">
 <INPUT TYPE="HIDDEN" NAME="MAX_FILE_SIZE" VALUE="2000000">
 <INPUT TYPE="FILE" Name ="uploadfile" SIZE="24" MAXLENGTH="80">
 <BR><BR>
 <INPUT TYPE="SUBMIT" VALUE="Upload File!" NAME="sendit">
 <INPUT TYPE="SUBMIT" VALUE="Cancel" NAME="cancelit"><BR>
</FORM>
</BODY>
</HTML>
-——————————————————————————————————————————————————————————————————————————————

upload.php:

<?php
 $uploaddir = "/usr/local/apache2/htdocs/xsgl/wenjian/";//去掉uploads
 
 $uploadfile = $uploaddir.$_FILES["uploadfile"]["name"];//upfile->uploadfile
 
 if ($_FILES["uploadfile"]["error"] > 0)
 {
  echo "Error: " . $_FILES["uploadfile"]["error"] . "<br />";
 }
 else
 {
  echo "Upload: " . $_FILES["uploadfile"]["name"] . "<br />";
  echo "Type: " . $_FILES["uploadfile"]["type"] . "<br />";
  echo "Size: " . ($_FILES["uploadfile"]["size"] / 1024) . " Kb<br />";
  echo "Stored in: " . $_FILES["uploadfile"]["tmp_name"];
 }
 
 if(move_uploaded_file($_FILES["uploadfile"]["tmp_name"], $uploadfile))//upfile->uploadfile
 {
  print "SUCCESS! \n";
  print_r($_FILES);
 }
 else
 {
  print "FAIL!\n";
  print_r($_FILES);
 }
?>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值