• upload 简单的封装


    upload 最简单的封装类

    <?php
        class Upload{
            public function Up($files){
                if($files['name'] > 1024*2*1024) die('文件过大');
                $arr = array('image/jpg','image/png','image/gif','image/jpeg');
                if(!in_array($files['type'],$arr)) die('文件类型不同');
                switch ($files['error']) {                                     // 上传文件的返回值
                    case 1:
                        echo "超过了 php.in 中 upload_max_filesize 选项限制的值";
                        break;
                    case 2:
                        echo "超过了 HTML 中 MAX_FILE_SIZE 选项限制的值";
                        break;
                    case 3:
                        echo "文件只有部分上传";
                        break;
                    case 4:
                        echo "没有文件上传";
                        break;
                    case 6:
                        echo "找不到临时文件";
                        break;
                    case 7:
                        echo "文件写入失效";
                        break;
                }
                $str = strrpos($files['name'],'.');
                $strs = substr($files['name'],$str);
                $filename = date('Ymd').time().rand().$strs;         // 上传名称随机
                $path = "./image/".date('Y-m-d').'/';
                if(!file_exists($path)){
                    mkdir($path,'0777',true);
                }
                $dir = $path.$filename;
                $res = move_uploaded_file($files['tmp_name'], $dir);    
                if($res){
                    return $dir;
                }else{
                    return 'no';
                }

            }
        }
    ?>

  • 相关阅读:
    poj 1236 Network of Schools 强连通分量 (添加几条边可以使整个图变成强连通图)
    poj 2363 Sightseeing ( 找次短路和最短路的条数 )
    poj 3013
    poj 1679 The Unique MST 最小生成树
    poj 1797 Heavy Transportation (spfa 最短路 )
    hdu 2680 Choose the best route (spfa)
    畅通工程续
    find the longest of the shortest
    SimpleDateFormate的使用
    SimpleDateFormate的使用
  • 原文地址:https://www.cnblogs.com/ghjbk/p/6581166.html
Copyright © 2020-2023  润新知