zoukankan      html  css  js  c++  java
  • 1、php文件上传保存。。。

     1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     2 <html xmlns="http://www.w3.org/1999/xhtml">
     3 <head>
     4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     5 <title>无标题文档</title>
     6 </head>
     7 
     8 <body>
     9 
    10 /*作业:上网找一个上图片传预览代码*/
    11 
    12 <form action="chuli.php" method="post" enctype="multipart/form-data">
    13 
    14 <input type="file" name="file" />
    15 
    16 <input type="submit" name="上传" />
    17 </form>
    18 </body>
    19 </html>
    20 
    21 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    22 <html xmlns="http://www.w3.org/1999/xhtml">
    23 <head>
    24 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    25 <title>无标题文档</title>
    26 </head>
    27 
    28 <body>
    29 <?php
    30 
    31 //上传文件的所有信息保存在数组里;
    32 //echo $_FILES["file"]["name"];
    33 //echo $_FILES["file"]["type"];//取文件类型
    34 //echo $_FILES["file"]["size"];//取文件大小
    35 //echo $_FILES["file"]["tmp_name"];//文件在服务器临时存放路径
    36 //
    37 //echo $_FILES["file"]["error"];//判断是否上传出错
    38 
    39 //文件上传
    40 //1、判断是否出错
    41 if($_FILES["file"]["error"])
    42 {
    43     echo "文件上传出错";
    44 }else
    45 {
    46     //2、加限制条件
    47     if($_FILES["file"]["type"] =="image/jpeg" && $_FILES["file"]["size"]<1024000 )
    48     {
    49         //处理文件名
    50         $str=date("YmdHisms",time());
    51         
    52         //3、造一个存储路径
    53         $url="./img/".$str.$_FILES["file"]["name"];
    54         
    55         //将路径的编码格式转换为国标,防止文件名乱码
    56         $FILEname=iconv("utf-8","gb2312",$url);
    57         
    58         if(file_exists($_FILEname))
    59         {
    60             echo "该文件已存在";
    61         }else
    62         {
    63         //存储
    64         move_uploaded_file($_FILES["file"]["tmp_name"],$filename);        
    65         }
    66                 //echo "可以上传";
    67     }else
    68     {
    69         
    70     echo "上传不符合要求";    
    71     }
    72 }
    73 
    74 ?>
    75 </body>
    76 </html>
    77 //文字未转码所有在这里面写!
  • 相关阅读:
    SQLServer之创建表值函数
    SQLServer之创建标量函数
    SQLServer之函数简介
    SQLServer之创建分布式事务
    SQLServer之创建隐式事务
    SQLServer之创建显式事务
    SQLServer之事务简介
    SQLServer之删除存储过程
    geoserver 添加图层数据
    geoserver入门
  • 原文地址:https://www.cnblogs.com/as1234as/p/5407616.html
Copyright © 2011-2022 走看看