PHP后台图片上传作品 接口
//把新图片添加到文件夹里
public function info($file=''){
$info = $file->validate(['ext'=>'jpg'])->rule('uniqid')->move(ROOT_PATH . 'public' . DS . 'uploads'); // 移动到框架应用根目录/public/uploads/ 目录下
if($info){
$info->getExtension();// 输出 jpg
$pic=$info->getFilename();// 输出 42a79759f284b767dfcb2a0197904287.jpg11.
return $pic;
}else{
echo $file->getError();// 上传失败获取错误信息
}
}
/**
* 作品添加
* name 谁的作品
* tel 电话
* img1 img2 img3 img4 作品图片
* address 拍摄地点
* addtime 拍摄时间
* picname 作品名称
* vote 投票情况
*/
public function zadd(){
$param=input('param.');
if(empty($param['tel'])){
return json(['code'=>2,'message'=>'tel不能为空']);
}
$files = request()->file('img1');
$files = [];
$param = [];
foreach ($files as $key => $file) {
$num = $key+1; //$key 下标
$img = 'img'.$num; //例如:img1
$param[$img] = $this->info($file);
}
$a=db('user')->where('tel',$param['tel'])->find();
if(empty($a)){
$data=db('user')->insertGetId(['name'=>$param['name'],'tel'=>$param['tel'],'img1'=>$param['img1'],'img2'=>$param['img2'],'img3'=>$param['img3'],'img4'=>$param['img4'],'address'=>$param['address'],'addtime'=>$param['addtime'],'picname'=>$param['picname'],'vote'=>$param['vote']]);
if($data){
return json(['code'=>1,'message'=>'作品添加成功']);
}else{
return json(['code'=>2,'message'=>'作品添加失败']);
}
}else{
return json(['code'=>3,'message'=>'该手机号已存在']);
}
}
/**
* 作品列表
* page 页数
* num 条数
*/
public function list(){
$param=input('param.');
if(empty($param['page'])){
$param['page']=1;
}
if(empty($param['num'])){
$param['num']=5;
}
$data=db('user')->page($param['page'],$param['num'])->select();
return json(['code'=>1,'data'=>$data]);
}
PHP后台图片上传作品 接口的更多相关文章
- APP客户端图片上传PHP接口
1.客户端 file_get_contents($_FILES['img']['tmp_name']) //获取临时目录下的上传文件流,加密传给接口 2.接口处理端 $img = file_get ...
- java后台图片上传预检失败解决方案
1.首先因为服务器端会先发送一个option请求到后台 在后台返回一个post给页面 页面在处理post请求给接口 2.先写一个过滤器, 我们自己定义一个过滤器 package com.adtime ...
- Asp.NetCoreWebApi图片上传接口(二)集成IdentityServer4授权访问(附源码)
写在前面 本文地址:http://www.cnblogs.com/yilezhu/p/9315644.html 作者:yilezhu 上一篇关于Asp.Net Core Web Api图片上传的文章使 ...
- html + js 实现图片上传,压缩,预览及图片压缩后得到Blob对象继续上传问题
先上效果 上传图片后(设置了最多上传3张图片,三张后上传按钮消失) 点击图片放大,可以使用删除和旋转按钮 (旋转功能主要是因为ios手机拍照后上传会有写图片被自动旋转,通过旋转功能可以调正) html ...
- spring boot + vue实现图片上传及展示
转载:https://blog.csdn.net/weixin_40337982/article/details/84031778 其中一部分对我很有帮助 转载记录下 首先,html页面: <! ...
- Kindeditor JS 富文本编辑器图片上传指定路径
js //================== KindEditor.ready(function (K) { var hotelid = $("#hotelid").val(); ...
- 百度ueditor的图片上传,前后端交互使用
百度ueditor的使用 一个文本编辑器,看了网上很多文档写的很乱,这里拾人牙慧,整理下怎么使用. 这个东西如果不涉及到图片附件上传,其实很简单,就是几个前端文件,直接引用,然后配置下ueditor. ...
- [转]微信小程序开发(二)图片上传+服务端接收
本文转自:http://blog.csdn.net/sk719887916/article/details/54312573 文/YXJ 地址:http://blog.csdn.net/sk71988 ...
- 前端js图片上传
前端js图片上传,原理用input type="file"获取图片然后把图片转换成base64编码传到后台. 图片上传 <!DOCTYPE html><html& ...
随机推荐
- c++计时
一.clock#include<ctime>clock_t start,end;start=clock();end=clock();cout<<start<<',' ...
- myeclipse的安装与配置和JUnit的简单使用
安装配置 首先根据自己电脑系统选择合适的JDK版本 http://www.oracle.com/technetwork/java/javase/downloads/index.html 这是JDK下载 ...
- Chat room
/* Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room ...
- nested exception is java.lang.NoClassDefFoundError: org/springframework/dao/support/PersistenceExceptionTranslator
该问题是少了一个spring-tx-的jar包,把该包加入到buildpath中就行了. 参考链接:http://blog.csdn.net/Rongbo_J/article/details/4666 ...
- eclipse中查找某一个字符串
想要完全匹配查找一个字符串,如iCard,而iCardSys或iiCard这种都不行,可以用正则表达式来查找,如下: 参考链接:http://blog.csdn.net/u014656992/arti ...
- 转:百度MySql5.7安装配置
原文地址:http://jingyan.baidu.com/article/8cdccae946133f315513cd6a.html MySQL 5.7以上版本的配置和以前有所不同,在这里与大家分享 ...
- java 银联接口开发
http://blog.sina.com.cn/s/blog_6c868c470100ys59.html 在线接口文档:http://wenku.baidu.com/link?url=EUgAuOKz ...
- idea+tomcat 端口占用
ntelliJ IDEA和Tomcat整合注意事项(转) 这两天一直在学习IDEA这个开发工具,今天再整合tomcat的时候遇到了问题,运行时总是报错,说是8080端口被占用,把我就搞的郁闷了,我就尝 ...
- 如何使用Log4j
如何使用Log4j? 1. Log4j是什么? Log4j可以帮助调试(有时候debug是发挥不了作 用的)和分析,要下载和了解更详细的内容,还是访问其官方网站吧: http://jakarta. ...
- idea配置springBoot项目热加载
1.在application.properties中禁用模板引擎缓存 比如freemarker:spring.freemarker.cache=false 2.在pom.xml中添加依赖 <de ...