<form enctype="multipart/form-data" action="3.php" method="post">
<input type="hidden" name="max_file_size" value="30000" />
选择文件:<input type="file" name="userfile" />
<input type="submit" value="上传文件" name="buttom"/>
</form><?php
header('Content-Type:text/html;charset=utf-8');
$example=substr($_FILES["userfile"]["name"],strrpos($_FILES["userfile"]["name"],".")+1);
$mydir="upfiles/".md5(time()).".".$example;
move_uploaded_file($_FILES["userfile"]["tmp_name"],$mydir);
?>求帮助!!!
2 回答
已采纳
MarlboroKay
TA贡献189条经验 获得超236个赞
应该要加类型和大小的判断
<?php if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_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"; } ?>
希望能帮到你,望采纳!
- 2 回答
- 0 关注
- 1490 浏览
相关问题推荐
添加回答
举报
0/150
提交
取消