zoukankan      html  css  js  c++  java
  • 文件上传图片

    要实现文件上传图片我们需要写出两个php文件,第一个php文件我们需要写出一个文件上传的页面,
    第二个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>

    <h1>文件上传</h1>
    <form action="upload.php" method="post" enctype="multipart/form-data">
    <input type="file" name="file" />
    <input type="submit" value="上传" />
    </form>
    </body>
    </html>





    <?php
    var_dump($_FILES["file"]);

    限制文件的类型
    限制文件的大小
    防止文件名重复

    一.防止文件名重复
    1.修改文件名
    流水号,时间戳+随机数+用户名

    2.建文件夹
    upload/20170317/lch/shangchuan/11.jpg

    3.保存文件

    if($_FILES["file"]["error"])
    {
    echo $_FILES["file"]["error"];
    }
    else
    {
    没有出错

    加限制条件

    if(($_FILES["file"]["type"]=="image/png" || $_FILES["file"]["type"]=="image/jpeg") && $_FILES["file"]["size"]<1024000)
    {

    防止文件名重复

    $filename = "./img/".time().$_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 "文件类型不对";
    }
    }
  • 相关阅读:
    10.3 noip模拟试题
    9.30 noip模拟试题
    9.29 奶牛练习题
    9.29noip模拟试题
    9.28noip模拟试题
    9.27 noip模拟试题
    二维数据结构学习
    9.26 noip模拟试题
    ContentProvider ContentResolver ContentObserver 内容:提供、访问、监听
    Cursor 游标
  • 原文地址:https://www.cnblogs.com/jc535201285/p/6566013.html
Copyright © 2011-2022 走看看