php基础练习--多文件上传

王朝学院·作者佚名  2016-08-28  
宽屏版  字体: 小 | 中 | 大 | 超大  

<html>

<head>

<meta charset="utf-8">

<title>index_uploads</title>

</head>

<body>

<form action="uploads.php" method="post" enctype="multipart/form-data">

<input type="file" name="file[]">

<br>

<input type="file" name="file[]">

<br>

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

</form>

</body>

</html>

index_uploads.php

<?php

header("content-type:text/html;charset=utf-8");

echo "<PRe>";

print_r($_FILES);

echo "</pre>";

$count = count($_FILES['file']['name']);

for ($i = 0; $i < $count; $i++) {

$tmpfile = $_FILES['file']['tmp_name'][$i];

$filefix = array_pop(explode(".", $_FILES['file']['name'][$i]));

$dstfile = "uploads/files/".time()."_".mt_rand().".".$filefix;

if (move_uploaded_file($tmpfile, $dstfile)) {

echo "<script>alert('succeed!');window.location.href='index_uploads.php';</script>";

} else {

echo "<script>alert('fail!');window.location.href='index_uploads.php';</script>";

}

}

uploads.php

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有