thinkphp和uploadfiy

上传页面 用的是bootstrap

<div class="col-sm-6"> <div style="width: 200px; height: 110px; float: left;"> <input type="hidden" name="photo" value="" id="data_photo" /> <input id="photo_file" name="photo_file" type="file" multiple="true" value="" /> </div> <div style="height: 110px; float: left;"> <img id="upload_img" src="" onerror="this.src='__PUBLIC__/Admin/img/no_img.jpg'" style="height: 100px" /> </div> </div>

  

$(function(){

            $('#photo_file').uploadify({
                'swf' :'__PUBLIC__/admin/swf/uploadify.swf',  //swf的相对路径
                'uploader': '{:U("Upload/upload")}',  //后台处理
                'buttonText': '上传头像', //按钮
                'height': 35,  //高度
                'fileTypeExts': '*.gif;*.jpg;*.png',  //上传类型
                'queueSizeLimit': 1, 
                'onUploadSuccess': function(file, data, response) { 

                    $("#upload_img").attr('src', '__PUBLIC__/Uploads/adminimg/' + data);  //预览效果
                    $("#data_photo").val(data);
                }
            });
        });

详细的
http://www.cnblogs.com/mofish/archive/2012/11/30/2796698.html
这个非常不错

  

public function upload(){
        $upload = new \Think\Upload();// ʵ�����ϴ���
        $upload->maxSize   =     3145728 ;// ���ø����ϴ���С
        $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// ���ø����ϴ�����
        $upload->rootPath  =     './Public/Uploads/adminimg/'; // ���ø����ϴ���Ŀ¼
        $upload->savePath  =     ''; // ���ø����ϴ����ӣ�Ŀ¼
        // �ϴ��ļ�
        $info   =   $upload->upload();
        if(!$info) {// �ϴ�������ʾ������Ϣ
            $this->error($upload->getError());
        }else{// �ϴ��ɹ�
            foreach($info as $file){
                echo $file['savepath'].$file['savename'];
            }
        }

    }

  

posted @ 2016-05-12 15:24  尘梦  阅读(230)  评论(0编辑  收藏  举报