php仿微信图片上传(php上传图片并压缩)

华为云服务器特价优惠火热进行中!

2核2G2兆仅需 38 元;4核4G3兆仅需 79 元。购买时间越长越优惠!更多配置及优惠价格请咨询客服。

合作流程:
1、点击链接注册/关联华为云账号:点击跳转
2、添加客服微信号:cloud7591,确定产品方案、价格方案、服务支持方案等;
3、客服协助购买,并拉微信技术服务群,享受一对一免费技术支持服务;
技术专家在金蝶、华为、腾讯原厂有多年工作经验,并已从事云计算服务8年,可对域名、备案、网站搭建、系统部署、AI人工智能、云资源规划等上云常见问题提供更专业靠谱的服务,对相应产品提供更优惠的报价和方案,欢迎咨询。

本篇文章给大家谈谈php仿微信图片上传,以及php上传图片并压缩对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

微信号:cloud7591
如需了解更多,欢迎添加客服微信咨询。
复制微信号

本文目录一览:

微信小程序之图片文件上传

选择图片:

上传图片:

小程序身份认证界面,点击上传地方的加号,选择相册或者拍照,进行上传,原图无压缩,最多上传3张(分别为身份证正面、反面和手持) 。

注:这边以laravel框架为例

1、定义文件上传路由:

2、在laravel框架中的config文件夹下的filesystems.php文件中配置上传路径

3、身份认证文件上传方法

1、在身份认证界面的wxml中绑定选择图片事件

2、在身份认证界面的js中定义上传图片的方法

3、上传成功后,将上传的文件地址存到数组中

用php实现手机拍照+本地相册实现图片上传功能,需要统一样式

PHP?很遗憾,PHP无法启动手机的拍照功能,这个需要调用手机的内部资源,通俗来说就是只有APP获取了这个权限才能去打开拍照公告,PHP是无法办到的。对于文件上传,目前还真的只有 input type="file",至于样式自己可以 去调试,关于你说的兼容性太差了,这个很不解,麻烦描述清楚点。

php微信拍照接口范例

    // 图片接口

    //拍照、本地选图

    var images = {

    localId: [],

    serverId: []

    };

    wx.chooseImage({

      success: function (res) {

        images.localId = res.localIds;

        alert('已选择 ' + res.localIds.length + ' 张图片');

      }

    });

  //上传图片

  $("#upload").click(function(){

    if (images.localId.length == 0) {

      alert('请先使用 chooseImage 接口选择图片');

      return;

    }

    var i = 0, length = images.localId.length;

    images.serverId = [];

    function upload() {

      wx.uploadImage({

        localId: images.localId[i],

        success: function (res) {

          i++;

          alert('已上传:' + i + '/' + length);

          images.serverId.push(res.serverId);

          if (i  length) {

            upload();

          }

        },

        fail: function (res) {

          alert(JSON.stringify(res));

        }

      });

    }

    upload();

  });

  // 5.4 下载图片

  $("#download").click(function(){

    if (images.serverId.length === 0) {

      alert('请先使用 uploadImage 上传图片');

      return;

    }

    var i = 0, length = images.serverId.length;

    images.localId = [];

    function download() {

      wx.downloadImage({

        serverId: images.serverId[i],

        success: function (res) {

          i++;

          alert('已下载:' + i + '/' + length);

          images.localId.push(res.localId);

          if (i  length) {

            download();

          }

        }

      });

    }

    download();

  });

php微信上传永久图片素材求代码

您好,这样的:

//素材

const MEDIA_FOREVER_UPLOAD_URL = '/material/add_material?';

const MEDIA_FOREVER_NEWS_UPLOAD_URL = '/material/add_news?';

const MEDIA_FOREVER_NEWS_UPDATE_URL = '/material/update_news?';

const MEDIA_FOREVER_GET_URL = '/material/get_material?';

const MEDIA_FOREVER_DEL_URL = '/material/del_material?';

const MEDIA_FOREVER_COUNT_URL = '/material/get_materialcount?';

const MEDIA_FOREVER_BATCHGET_URL = '/material/batchget_material?';

/**

* 上传临时素材,有效期为3天(认证后的订阅号可用)

* 注意:上传大文件时可能需要先调用 set_time_limit(0) 避免超时

* 注意:数组的键值任意,但文件名前必须加@,使用单引号以避免本地路径斜杠被转义

* 注意:临时素材的media_id是可复用的!

* @param array $data {"media":'@Path\filename.jpg'}

* @param type 类型:图片:image 语音:voice 视频:video 缩略图:thumb

* @return boolean|array

*/

public function uploadMedia($data, $type){

if (!$this-access_token !$this-checkAuth()) return false;

//原先的上传多媒体文件接口使用 self::UPLOAD_MEDIA_URL 前缀

$result = $this-http_post(self::API_URL_PREFIX.self::MEDIA_UPLOAD_URL.'access_token='.$this-access_token.'type='.$type,$data,true);

if ($result)

{

$json = json_decode($result,true);

if (!$json || !empty($json['errcode'])) {

$this-errCode = $json['errcode'];

$this-errMsg = $json['errmsg'];

return false;

}

return $json;

}

return false;

}

/**

* 获取临时素材(认证后的订阅号可用)

* @param string $media_id 媒体文件id

* @param boolean $is_video 是否为视频文件,默认为否

* @return raw data

*/

public function getMedia($media_id,$is_video=false){

if (!$this-access_token !$this-checkAuth()) return false;

//原先的上传多媒体文件接口使用 self::UPLOAD_MEDIA_URL 前缀

//如果要获取的素材是视频文件时,不能使用https协议,必须更换成http协议

$url_prefix = $is_video?str_replace('https','http',self::API_URL_PREFIX):self::API_URL_PREFIX;

$result = $this-http_get($url_prefix.self::MEDIA_GET_URL.'access_token='.$this-access_token.'media_id='.$media_id);

if ($result)

{

if (is_string($result)) {

$json = json_decode($result,true);

if (isset($json['errcode'])) {

$this-errCode = $json['errcode'];

$this-errMsg = $json['errmsg'];

return false;

}

}

return $result;

}

return false;

}

/**

* 上传永久素材(认证后的订阅号可用)

* 新增的永久素材也可以在公众平台官网素材管理模块中看到

* 注意:上传大文件时可能需要先调用 set_time_limit(0) 避免超时

* 注意:数组的键值任意,但文件名前必须加@,使用单引号以避免本地路径斜杠被转义

* @param array $data {"media":'@Path\filename.jpg'}

* @param type 类型:图片:image 语音:voice 视频:video 缩略图:thumb

* @param boolean $is_video 是否为视频文件,默认为否

* @param array $video_info 视频信息数组,非视频素材不需要提供 array('title'='视频标题','introduction'='描述')

* @return boolean|array

*/

public function uploadForeverMedia($data, $type,$is_video=false,$video_info=array()){

if (!$this-access_token !$this-checkAuth()) return false;

//#TODO 暂不确定此接口是否需要让视频文件走http协议

//如果要获取的素材是视频文件时,不能使用https协议,必须更换成http协议

//$url_prefix = $is_video?str_replace('https','http',self::API_URL_PREFIX):self::API_URL_PREFIX;

//当上传视频文件时,附加视频文件信息

if ($is_video) $data['description'] = self::json_encode($video_info);

$result = $this-http_post(self::API_URL_PREFIX.self::MEDIA_FOREVER_UPLOAD_URL.'access_token='.$this-access_token.'type='.$type,$data,true);

if ($result)

{

$json = json_decode($result,true);

if (!$json || !empty($json['errcode'])) {

$this-errCode = $json['errcode'];

$this-errMsg = $json['errmsg'];

return false;

}

return $json;

}

return false;

}

/**

* 上传永久图文素材(认证后的订阅号可用)

* 新增的永久素材也可以在公众平台官网素材管理模块中看到

* @param array $data 消息结构{"articles":[{...}]}

* @return boolean|array

*/

public function uploadForeverArticles($data){

if (!$this-access_token !$this-checkAuth()) return false;

$result = $this-http_post(self::API_URL_PREFIX.self::MEDIA_FOREVER_NEWS_UPLOAD_URL.'access_token='.$this-access_token,self::json_encode($data));

if ($result)

{

$json = json_decode($result,true);

if (!$json || !empty($json['errcode'])) {

$this-errCode = $json['errcode'];

$this-errMsg = $json['errmsg'];

return false;

}

return $json;

}

return false;

}

/**

* 修改永久图文素材(认证后的订阅号可用)

* 永久素材也可以在公众平台官网素材管理模块中看到

* @param string $media_id 图文素材id

* @param array $data 消息结构{"articles":[{...}]}

* @param int $index 更新的文章在图文素材的位置,第一篇为0,仅多图文使用

* @return boolean|array

*/

public function updateForeverArticles($media_id,$data,$index=0){

if (!$this-access_token !$this-checkAuth()) return false;

if (!isset($data['media_id'])) $data['media_id'] = $media_id;

if (!isset($data['index'])) $data['index'] = $index;

$result = $this-http_post(self::API_URL_PREFIX.self::MEDIA_FOREVER_NEWS_UPDATE_URL.'access_token='.$this-access_token,self::json_encode($data));

if ($result)

{

$json = json_decode($result,true);

if (!$json || !empty($json['errcode'])) {

$this-errCode = $json['errcode'];

$this-errMsg = $json['errmsg'];

return false;

}

return $json;

}

return false;

}

/**

* 获取永久素材(认证后的订阅号可用)

* 返回图文消息数组或二进制数据,失败返回false

* @param string $media_id 媒体文件id

* @param boolean $is_video 是否为视频文件,默认为否

* @return boolean|array|raw data

*/

public function getForeverMedia($media_id,$is_video=false){

if (!$this-access_token !$this-checkAuth()) return false;

$data = array('media_id' = $media_id);

//#TODO 暂不确定此接口是否需要让视频文件走http协议

//如果要获取的素材是视频文件时,不能使用https协议,必须更换成http协议

//$url_prefix = $is_video?str_replace('https','http',self::API_URL_PREFIX):self::API_URL_PREFIX;

$result = $this-http_post(self::API_URL_PREFIX.self::MEDIA_FOREVER_GET_URL.'access_token='.$this-access_token,self::json_encode($data));

if ($result)

{

if (is_string($result)) {

$json = json_decode($result,true);

if (isset($json['errcode'])) {

$this-errCode = $json['errcode'];

$this-errMsg = $json['errmsg'];

return false;

}

return $json;

}

return $result;

}

return false;

}

/**

* 删除永久素材(认证后的订阅号可用)

* @param string $media_id 媒体文件id

* @return boolean

*/

public function delForeverMedia($media_id){

if (!$this-access_token !$this-checkAuth()) return false;

$data = array('media_id' = $media_id);

$result = $this-http_post(self::API_URL_PREFIX.self::MEDIA_FOREVER_DEL_URL.'access_token='.$this-access_token,self::json_encode($data));

if ($result)

{

$json = json_decode($result,true);

if (!$json || !empty($json['errcode'])) {

$this-errCode = $json['errcode'];

$this-errMsg = $json['errmsg'];

return false;

}

return true;

}

return false;

}

/**

* 获取永久素材列表(认证后的订阅号可用)

* @param string $type 素材的类型,图片(image)、视频(video)、语音 (voice)、图文(news)

* @param int $offset 全部素材的偏移位置,0表示从第一个素材

* @param int $count 返回素材的数量,取值在1到20之间

* @return boolean|array

* 返回数组格式:

* array(

* 'total_count'=0, //该类型的素材的总数

* 'item_count'=0, //本次调用获取的素材的数量

* 'item'=array() //素材列表数组,内容定义请参考官方文档

* )

*/

public function getForeverList($type,$offset,$count){

if (!$this-access_token !$this-checkAuth()) return false;

$data = array(

'type' = $type,

'offset' = $offset,

'count' = $count,

);

$result = $this-http_post(self::API_URL_PREFIX.self::MEDIA_FOREVER_BATCHGET_URL.'access_token='.$this-access_token,self::json_encode($data));

if ($result)

{

$json = json_decode($result,true);

if (isset($json['errcode'])) {

$this-errCode = $json['errcode'];

$this-errMsg = $json['errmsg'];

return false;

}

return $json;

}

return false;

}

/**

* 获取永久素材总数(认证后的订阅号可用)

* @return boolean|array

* 返回数组格式:

* array(

* 'voice_count'=0, //语音总数量

* 'video_count'=0, //视频总数量

* 'image_count'=0, //图片总数量

* 'news_count'=0 //图文总数量

* )

*/

public function getForeverCount(){

if (!$this-access_token !$this-checkAuth()) return false;

$result = $this-http_get(self::API_URL_PREFIX.self::MEDIA_FOREVER_COUNT_URL.'access_token='.$this-access_token);

if ($result)

{

$json = json_decode($result,true);

if (isset($json['errcode'])) {

$this-errCode = $json['errcode'];

$this-errMsg = $json['errmsg'];

return false;

}

return $json;

}

return false;

}

php仿微信图片上传的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于php上传图片并压缩、php仿微信图片上传的信息别忘了在本站进行查找喔。

发布于 2023-03-25 06:03:19
收藏
分享
海报
42
目录

    忘记密码?

    图形验证码

    复制成功
    微信号: cloud7591
    如需了解更多,欢迎添加客服微信咨询。
    我知道了