zoukankan      html  css  js  c++  java
  • 图片上传到指定的文件夹(规范化上传)

    <!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>
    <style>
    *{
         margin:0 auto;
        }
    .div1{
          830px;
          height:133px;
          background-image:url(images/bg_111.jpg);
        }
    .div2{
          830px;
          height:30px;
          background-image:url(images/bg_110.jpg);
        }
    #upload
    {
         830px;
         height:133px;
         text-align:center;    
         margin-top:100px;
        }
    
    </style>
    
    
    
    </head>
    <body>
          <div class="div1">
          </div>
          <div id="upload">
          <form method="post" name="form1"  action="index.php" enctype="multipart/form-data">
                 <input type="hidden" name="MAX_FILE_SIZE" value="100000000" />
           选择上传文件:
                 <input type="file" name="up_picture" />
                 <input type="image" name="imageField2" src="images/bg_00.jpg"  />
                 <input type="image" name="imageField3" src="images/bg_000.jpg" />
          </form>
          </div>
          <center>
               <?php
            if(!empty($_FILES['up_picture']['name'])){     //判断上传内容是否为空
                 if($_FILES['up_picture']['error']>0){     //判断文件是否可以上传到服务器
                echo"上传错误";
                switch($_FILES['up_picture']['error']){
                    case 1:
                        echo"上传文件大小超出配置文件规定值";
                    break;
                    case 2:
                        echo"上传文件大小超出表单中约定值";
                    break;
                    case 3:
                         echo"上传文件不全";
                    break;
                    case 4:
                        echo"没有上传文件";
                    break;
                    }      
                }else{
                    list($maintype,$subtype)=explode("/",$_FILES['up_picture']['type']);
                    if($maintype!="image"&&$subtype!="pjpeg"){
                        echo"上传文件格式不正确";
                        }else{
                            if(!is_dir("./upfile/")){   //判断指定目录是否存在
                                mkdir("./upfile/");     //创建目录
                                }
                            $path='./upfile/'.time().strtolower(strstr($_FILES['up_picture']['name'],"."));                     //定义上传文件的名字和上传位置
                            if(is_uploaded_file($_FILES['up_picture']['tmp_name'])){ //判断文件是否是http.post上传
                                if(!move_uploaded_file($_FILES['up_picture']['tmp_name'],$path)){ //执行上传操作
                                    echo"上传失败";
                                    }else{
                                        echo"上传成功";
                                        }
                                }else{
                                    echo"上传文件不合法";
                                    }
                            }
                    }
                }
          ?>
          </center>
          <div class="div2">
          </div>
        
     
    </body>
    </html>
  • 相关阅读:
    python的类的继承和多继承
    python的类访问控制、私有属性
    python的面向对象、类方法和静态方法
    python的序列化和反序列化
    python高阶函数、柯里化、装饰器、参数注解
    python函数参数、参数解构、作用域、递归及匿名函数
    python内置函数列表解析、生成器
    python内置函数字典(dict)
    python内置函数集合(set)
    定制自己的打印函数---进阶篇
  • 原文地址:https://www.cnblogs.com/kangshuai/p/4863065.html
Copyright © 2011-2022 走看看