
php大神来,post提交文本或者提交文件 255
1个回答
展开全部
前端 index.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 method="post" enctype="multipart/form-data" action="./manage.php" name="">
<input type="file" name="uploadfile" id="uploadfile" >
<input type="submit" name="upload" id="upload" value="上传">
<form>
</body>
</html>
后端manage.php与index.php同一层
<?php
if(!empty($_FILES["uploadfile"]['tmp_name'])){
$up_name = $_FILES["uploadfile"];
$up_size = $up_name["size"];
$up_type = $up_name["type"];
$up_path = $up_name['tmp_name'];
$up_fname = $up_name['name'];
$exten = pathinfo($up_fname,PATHINFO_EXTENSION);
$objname = date('YmdHis',time());
$save = $objname.'.'.$exten;
$max_size = '314572800';//300M 1024*1024*300
$up_limit = array("application/msword","text/html","application/pdf","application/vnd.ms-powerpoint","text/plain","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
if(in_array($up_type,$up_limit) && $up_size <= $max_size && $up_size>=0) {
if(move_uploaded_file($up_path,$save)) {
$msg = '上传成功';
}
else {
$msg = '上传失败';
}
}
else {
$msg = '上传类型或大小不符合';
}
}
else {
$msg = '无上传文件';
}
echo $msg;
?>
更多追问追答
追问
不能上传图片吗?
直接HTTP POST提交字节集就可以了吗?
追答
可以啊
你把 if(in_array($up_type,$up_limit) && $up_size =0)
改成if( 1)或者去掉这个条件,你可以上传任何文件且大小不限制。
in_array($up_type,$up_limit) 限制上传文件的类型
$up_size =0限制文件的大小。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |