• php图片上传


    <?php
    //require_once '../include/adminfunction.php';
    error_reporting(0);/*设置php的报错级别*/

    //设置PHP执行超时时间
    ini_set("max_execution_time", "80"); //最大时间20 秒

    //修改此次的最大运行内存
    ini_set("memory_limit", 1024*1024*40); //最大内存 Byte 20 兆
    define('VERSON',"lexiang");/*定义一个常量*/
    date_default_timezone_set('Asia/Shanghai');/*用在脚本中所有日期时间函数的默认时区*/
    //模板程序编码,要和模板的编码对上。 可选GBK或者UTF-8
    $default_soft_lang = "utf-8";
    header("Content-Type: text/html; charset=".$default_soft_lang."");

    //require_once "../public/db.config.php";

    if(!isset($_SESSION)){
    session_start();
    }
    if((count($_POST)>=1 ||count($_GET)>=1 ) && $_SERVER["SCRIPT_NAME"]!="/taodi/admin/index.php"){
    //exit("<script language='JavaScript'>alert('演示版禁止修改!');history.go(-1);<///script>");
    }
    ?>
    <!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>
    <table>
    <?php
    function getImageExt($fileName)
    {
    $arrFile=explode('.',strtolower($fileName));
    $fileExt=$arrFile[count($arrFile)-1];
    return $fileExt;
    }

    if (is_uploaded_file($_FILES['upfile']['tmp_name'])){

    $upfile=$_FILES["upfile"];

    $name = $upfile["name"];
    $type = $upfile["type"];
    $size = $upfile["size"];
    $tmp_name = $upfile["tmp_name"];
    $error = $upfile["error"];

    switch ($type) {
    case 'image/jpg' :
    if(getImageExt($name)=="jpg" || getImageExt($name)=="jpeg") $ok=1;
    break;
    case 'image/jpeg' :
    if(getImageExt($name)=="jpg" || getImageExt($name)=="jpeg") $ok=1;
    break;
    case 'image/pjpeg' :
    if(getImageExt($name)=="jpg" || getImageExt($name)=="jpeg") $ok=1;
    break;
    case 'image/gif' :
    if(getImageExt($name)=="gif") $ok=1;
    break;
    case 'image/png' :
    if(getImageExt($name)=="png") $ok=1;
    break;
    case 'image/x-png' :
    if(getImageExt($name)=="png") $ok=1;
    break;
    }
    }
    ?>
    <form action="" enctype="multipart/form-data" method="post" name="upform">
    <tr>
    <td height="110" bgcolor="#FFFFFF" class="STYLE2">LOGO上传:</td>
    <td height="110" bgcolor="#FFFFFF" class="STYLE2">
    <?php
    if($ok && $error=='0'){
    move_uploaded_file($tmp_name,'../img/'.$name);
    echo "<span style=\"color:red\">上传成功</span><br>";
    }

    if(is_uploaded_file($_FILES['upfile']['tmp_name']) && $ok!=1){
    echo "<span style=\"color:red\">上传失败,请确认您上传的图片为:jpg jpeg gif png格式!</span><br>";
    }

    ?>
    <input name="upfile" type="file">
    <input type="submit" value="上传"><br />
    <span style="color:#F00">标准尺寸:长<240px 宽<100px</span><br />
    <span style="color:#36C">文件会上传到站点相对路径的img/目录</span>
    </td>
    <td height="80" bgcolor="#FFFFFF" class="STYLE4">
    支持上传的图片类型为:jpg jpeg gif png格式!<br>
    <span style="color:#F00">注意:如果上传的文件名与原目录的文件名相同,此操作会自动覆盖原来的图片。</span>
    </td>
    </tr>
    </form>
    </table>
    </body>
    </html>

  • 相关阅读:
    linux下socket编程-TCP
    python正则表达式练习篇2
    python正则表达式练习篇
    python正则表达式基础篇
    Jmeter应用初步介绍
    数据库清除重复数据
    Nginx 获取真实 IP 方案
    Mac 实用工具bash-comletion介绍安装
    MySQL的binlog数据如何查看
    Mybatlis SQL 注入与防范
  • 原文地址:https://www.cnblogs.com/bafeiyu/p/2851426.html
Copyright © 2020-2023  润新知