php大神来,post提交文本或者提交文件 255

帮我写一份代码好么,post提交文本或者文件数据后在ftp空间上建立一个文本文档或者文件... 帮我写一份代码好么,post提交文本或者文件数据后在ftp空间上建立一个文本文档或者文件 展开
 我来答
邓国权02
2017-08-11 · TA获得超过153个赞
知道小有建树答主
回答量:162
采纳率:66%
帮助的人:35.8万
展开全部

前端 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限制文件的大小。
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式