HTML 部分:

//引入jquery
<script src="/public/js/jquery.ajaxfileupload.js"></script>
//HTML部分
<div class="upld">
    <div class="col-xs-3 box">
        <a href="javascript:;" class="a-upload">
            <input type="file" name="file[]" id="">
        </a>
        <p>+</p>
        <!-- <a href="javascript:;" class="file">选择文件
            <input type="file" name="" id="">
        </a> -->
    </div>
    <div class="col-xs-3 box">
        <a href="javascript:;" class="a-upload">
            <input type="file" name="file[]" id="">
        </a>
        <p>+</p>
    </div>
    <div class="col-xs-3 box">
        <a href="javascript:;" class="a-upload">
            <input type="file" name="file[]" id="">
        </a>
        <p>+</p>
    </div>
</div>      
//jquery部分
$("input[type='file']").ajaxfileupload({
    action: "{:U('Portal/News/ajaxFileUpload')}",
    params: {
        extra: 'info'
    },
    onComplete: function(res) {

        if (res.code == '0'){
            path = res.res['0'];
            var img = "<img src='"+path+"'>";
            $(this).parent().next().html(img)
        } else{
            alert(res.msg)
        }
    },

});

php部分:

public function ajaxFileUpload(){
        $upload = new \Think\Upload();// 实例化上传类

        $upload->maxSize   =     10485760 ;// 设置附件上传大小 10M
        $upload->exts      =     array('zip', 'rar', '7z','jpg','jpeg','png','gif');// 设置附件上传类型
        $upload->rootPath  =     C('UPLOADPATH'); // 设置附件上传根目录
        $upload->savePath  =     'guestbook/'; // 设置附件上传(子)目录
        // 上传文件 
        $info   =   $upload->upload();
        if(!$info) {// 上传错误提示错误信息
            ajaxReturn('1',$info);
        }else{// 上传成功
            $re = array();
            foreach ($info as $k => $v) {
                $re[] = sp_get_asset_upload_path($v['savepath'] . $v['savename']);
            }
            ajaxReturn('0','success',$re);
        }
    }

    private function upload(){

        $upload = new \Think\Upload();// 实例化上传类

        $upload->maxSize   =     10485760 ;// 设置附件上传大小 10M
        $upload->exts      =     array('zip', 'rar', '7z','jpg','jpeg','png','gif');// 设置附件上传类型
        $upload->rootPath  =     C('UPLOADPATH'); // 设置附件上传根目录
        $upload->savePath  =     'guestbook/'; // 设置附件上传(子)目录
        // 上传文件 
        $info   =   $upload->upload();

        if(!$info) {// 上传错误提示错误信息
            return '';
        }else{// 上传成功
            $re = array();
            foreach ($info as $k => $v) {
                $re[] = $v['savepath'] . $v['savename'];
            }
            return $re;
        }
    }

下载:jquery.ajaxfileupload

php实现redis延时队列

写了一个简单的类实现 使用方法 $class = new RedisDelayQueue(); $class->execute(); <?php namespace app\common\service; class RedisDelay { ...

阅读全文

php获取包含10w个手机号的txt文件(逗号隔开)

txt文件格式如下 13000000000,13000000005,13000000403,13001010129,13001010688,13001010838,13001016389,13001019538,13001030005,13001042700,13001047495...

阅读全文

php使用Carbon获取2个日期之间的日期

<?php use Carbon\CarbonPeriod; $period = CarbonPeriod::create('2018-06-14', '2018-06-20'); // Iterate over the period fore...

阅读全文

欢迎留言