博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
js单图片上传
阅读量:4354 次
发布时间:2019-06-07

本文共 2724 字,大约阅读时间需要 9 分钟。

 

//这里一定要写name 后台就是通过name接受内容
{if condition="($company_info.cover_img)"}
{else/}
{/if}

 

前台js

 

 
$('#file').change(function(){        if (this.files && this.files[0]) {            var objUrl = getObjectURL(this.files[0]);            console.log(objUrl);            var data = new FormData($('#form1')[0]);            console.log($('#form1'));            console.log(data);            $.ajax({                 url: "{:url('advert/upload_img')}",                 type: 'POST',                 data: data,                async: false,                dataType: 'JSON',                 processData: false,                 contentType: false,            }).done(function(ret){             // alert(ret.path_img);                if(ret.error==1){                    $('#cover_img').attr('src',ret.path_img);                    $('#cover_img').css('width','100px');                    $('#cover_img').css('height','100px');                }else{                    alert('上传失败');                }            });         }    })

 

 

 

 
function getObjectURL(file) {                       var url = null;            if (window.createObjectURL != undefined) { // basic                url = window.createObjectURL(file);            } else if (window.URL != undefined) { // mozilla(firefox)                url = window.URL.createObjectURL(file);            } else if (window.webkitURL != undefined) { // webkit or chrome                url = window.webkitURL.createObjectURL(file);            }            return url;    }
 

 

 

 

 

后台php

public function upload(){        $file = request()->file('head_img');        $path=str_replace('\\', '/', 'upload/box');        if (!is_dir($path)) {            mkdir($path, 0777,true);        }        // $path=company_coverimg_path('854');        if($file){            $info = $file->move($path);            if($info){                $path_img ='/'.$path.'/'.$info->getSaveName();                 $data['path_img']=$path_img;                $data['error']=1;            }else{                // 上传失败获取错误信息                $msg = $file->getError();                $data['error']=2;                $data['msg']=$msg;            }        }        echo json_encode($data);    }

 

 

 

 

 

 

<scroll-view scroll-y="true" style="height: 200rpx;">

<view style="background: red; width: 200px; height: 100px; display: inline-block" ></view>
<view style="background: green; width: 200px; height: 100px; display: inline-block"></view>
<view style="background: blue; width: 200px; height: 100px; display: inline-block"></view>
<view style="background: yellow; width: 200px; height: 100px; display: inline-block"></view>
</scroll-view>

转载于:https://www.cnblogs.com/chentailin/p/8991460.html

你可能感兴趣的文章
HTTP基础知识
查看>>
mariadb(mysql)从库relaylog损坏无法同步的处理方法
查看>>
图论——LCA、强联通分量、桥、割顶、二分图最大匹配、网络流
查看>>
CDH集成Kafka,两种方式:离线、在线
查看>>
【原】Google浏览器刷新
查看>>
urllib2的GET和POST请求(五)
查看>>
树状数组入门及树状数组由来
查看>>
UUID介绍与生成的方法
查看>>
nginx高级玩法之根据来源ip分流
查看>>
16. 3Sum Closest
查看>>
BFS:Nightmare(可返回路径)
查看>>
vijos 1557:bzoj:1413: [ZJOI2009]取石子游戏
查看>>
hackerrank Alex对战Fedor
查看>>
list,string,tuple,dictionary之间的转换
查看>>
Action<T> 泛型委托 在跨线程访问控件委托中的应用
查看>>
主机屋----常用程序安装链接数据库教程
查看>>
JQuery传值给.ashx乱码
查看>>
java1.7之后的比较器特别之处
查看>>
Jmeter之分布式执行测试
查看>>
Python入门二
查看>>