• PHP文件上传


    1.主页面

    <!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 action="shangchuan.php" method="post" enctype="multipart/form-data">
        <input type="file" name="file" />
        <input type="submit" value="上传" />
    </form>
    </body>
    </html>

    2.上传文件处理页面

    <?php
    
    
    //1.控制上传文件的类型
    //2.控制上传文件的大小
    //3.防止文件名重复
        //修改保存的文件名
            //用户名+时间戳+随机数+文件名
            //流水号
            
        //使用文件夹
            // public/lch/2017-2-12/1.jpg
            
    //4.保存文件
    
    
    //判断文件上传是否出错
    if($_FILES["file"]["error"])
    {
        echo $_FILES["file"]["error"];
    }
    else
    {
        //控制上传文件的类型,大小
        if(($_FILES["file"]["type"]=="image/jpeg" || $_FILES["file"]["type"]=="image/png") && $_FILES["file"]["size"]<1024000)
        {
            //找到文件存放的位置
            $filename = "./file/".date("YmdHis").$_FILES["file"]["name"];
            
            //转换编码格式
            $filename = iconv("UTF-8","gb2312",$filename);
            
            //判断文件是否存在
            if(file_exists($filename))
            {
                echo "该文件已存在!";
            }
            else
            {
                //保存文件
                move_uploaded_file($_FILES["file"]["tmp_name"],$filename);
            }
        }
        else
        {
            echo "文件类型不正确!";
        }
    }
  • 相关阅读:
    kill tomcat with netstat
    windows cmd命令显示UTF8设置
    rtx没有振动功能
    手动加载rvm
    RESTful Java client with Apache HttpClient
    Set Up Git on windows also use github
    lcs.py 最长公共子串算法
    如何:对代理使用 IP 切换
    这个博客站点不错
    a case study
  • 原文地址:https://www.cnblogs.com/chaochao00o/p/6277054.html
Copyright © 2020-2023  润新知