上传文件

1.开启php_fileinfo.dll  拓展(php.ini)

2. php端代码

public function dotest(){
        $file = Input::file('myfile');
        if($file -> isValid()){
            $clientName = $file -> getClientOriginalName();
            $tmpName = $file ->getFileName(); // 缓存在tmp文件夹中的文件名
            $realPath = $file -> getRealPath();     //获取真实绝对路径
            $extension = $file -> getClientOriginalExtension(); //上传文件的后缀\
            $mimeTye = $file -> getMimeType();
            
            $newName = md5(date('ymdhis').$clientName).".".$extension;    //重新组装文件名
            $path = $file -> move('../storage/app/uploads',$newName);
        }
        
    }

 

3.html代码

<form method="post" enctype="muitipart/form-data" target="hiddenwin" id="ajaxForm" action="{{url('home/cateDoc/dotest')}}" class="form-condensed">
                                <table class="table table-form">
                                    <tbody>
                                        <tr>
                                            <th>文档类型名称:</th>
                                            <td><div class="required required-wrapper"></div>
                                                 <input type="file" name="myfile" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <td></td>
                                            <td>
                                            <button type="submit" id="submit" class="btn btn-submit btn-primary">
                                                保存
                                            </button><a href="javascript:history.go(-1);" class="btn btn-back">返回</a>
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                            </form>

 

posted @ 2015-09-23 17:46  天道酬勤,坚持!  阅读(244)  评论(0编辑  收藏  举报