• laravel 判断上传文件的类型和后缀


    学习源头:

    https://blog.csdn.net/ddjjll8877/article/details/52249965

    class FileUpdateController extends BaseController{
    
        public function fileUpdate(){
            return View::make('file_input.file_update');
        }
    
        public function fileGet(){
            //获取文件
            $file= Input::file('file_type');
            if($file->isValid()){
                //方式一,文件类型方式
                $this->saveFiles_1($file);
                //方式二,文件后缀方式
                $this->saveFiles_2($file);
            }
        }
    
        public function saveFiles_2($file){
            //文件后缀
            $fileTypes = array('html','mp4','pdf','doc','txt');
            //获取文件类型后缀
            $extension = $file->getClientOriginalExtension();
            //是否是要求的文件
            $isInFileType = in_array($extension,$fileTypes);
            if($isInFileType){
                $savePath = public_path('').'/files_store';
                $filename = 'haha.'.$extension;
                $file->move($savePath,$filename);
            }else{
                echo "文件格式不合法";
                return;
            }
        }
    
        public function saveFiles_1($file){
            //文件类型
            $fileTypes = array('audio/mpeg','text/html','video/mp4','application/pdf','application/msword','text/plain');
            if(in_array($file->getMimeType(),$fileTypes)) {
                // 保存文件
                return '文件格式合法';
            }
            else {
                // 
                return '文件格式不合法'.$file->getMimeType();
            }
        }
    }
  • 相关阅读:
    A*算法实现 八数码问题
    poj 1077 Eight(bfs,dbfs, A*)
    poj 1729 Jack and Jill (搜索,bfs)
    poj 4105 拯救公主(bfs)
    poj4091The Closest M Points(KD-tree)
    资源整理
    推荐 VS2010入门教程—鸡啄米
    Cstring的使用
    VC 中TEXT、_T、L的区别
    电脑内存和CPU的关系
  • 原文地址:https://www.cnblogs.com/djwhome/p/9173462.html
Copyright © 2020-2023  润新知