PHP文件上传

昨天想做一个文件上传的页面,网上搜了一些资料,写得有够模糊的,后来自己研究了一段时间,终于知道该怎么做了,总共做了两个页面,一个是upload.html,一个是upload.php,现将两个页面的代码附上,

upload.html:

<html>

<head> <title>文件上传</title> <LINK href="../css/table.css" rel=stylesheet type=text/css> </head> <body style="margin-left: 0; margin-right: 0; margin-top: 5; margin-bottom: 0">

<form enctype="multipart/form-data" action="upload.php" method="POST">

<table border="0" cellspacing="0" cellpadding="0" align="center" width = "60%">

<tr> <td><div align="center" >

<table border="0" cellspacing="1" cellpadding="3" align="center" width = "100%">

<tr> <td align="center" bgcolor="#4c8ab4" colspan="10"><p align="left"><font size="2">文件上传</font></td> </tr>

<tr align="center" > <td bgcolor="#4c8ab4" align="center" width="70%"><p align="center"> <font size="2"><input name="userfile1" type="file" /><br /> </font> </p></td> <td bgcolor="#4c8ab4" align="center"><p align="center"> <font size="2"><input type="submit" value="上传" /> </font> </p></td> </tr>

</table> </div> </td>

</tr>

</table>

</form>

</body>

</html>

 

 

upload.php:

<?

$uploaddir = '../DB/'; //上传的目录

if(!is_dir($uploaddir)){mkdir($uploaddir,0777); }

$uploadfile1 = $uploaddir."restore.db";

if($_FILES['userfile1']['name']!=""){ move_uploaded_file($_FILES['userfile1']['tmp_name'], $uploadfile1); }

echo "<script language=javascript>alert('上传成功,点击返回!');location='upload.html'</script>";

?>

 

 

上传的动作就在这句上:move_uploaded_file($_FILES['userfile1']['tmp_name'], $uploadfile1),其中['tmp_name']是上传文件框所存储的临时文件名,因为PHP上传的时候,它有将上传的文件先传到一个临时的文件区,这个文件区在php.ini中可以配置,如何没有将它移动的话,那么当这个页面销毁的时候,此文件也会跟着被销毁。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值