PHP code example of shuishuiafeng / webuploader-cropper
1. Go to this page and download the library: Download shuishuiafeng/webuploader-cropper library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
shuishuiafeng / webuploader-cropper example snippets
// 图片服务器的域名设置,拼接保存在数据库中的相对地址,可通过web进行展示
'wechat_options' => [
'debug' => true,
'app_id' =>"wxxxxxxxxxxxx",
'secret' =>'xxxxxxxxxxxxxxxxxx',
'token' =>'xxxxxxxxxxx',
'aes_key'=>'xxxxxxx',
'log' => [
'level' => 'debug',
'file' => \Yii::getAlias('@mobile/runtime/logs/easywechat.log')
],
]
// ActiveForm
echo $form->field($model, 'file')->widget('dmdedu\FileInput', [
]);
// 非 ActiveForm
echo '<label class="control-label">图片</label>';
echo \dmdedu\FileInput::widget([
'model' => $model,
'attribute' => 'file',
]);
//距离在formbuilder中的form中使用
'image'=>[
'type'=>'widget',
'class'=>\dmdedu\FileInput::className(),
'clientOptions'=>[
'accept' => [
'extensions' => 'gif,jpg,jpeg,bmp,png',
'mimeTypes' => 'image/gif,image/jpg,image/jpeg,image/bmp,image/png'
],
'pick' => [//多图模式默认关闭
'class' => 'btn-default',
'innerHTML' => '图'
],
/*非截图的设置如下*/
'screenshot' => false,//如果是截图就是base64流,不是截图就是普通文件上传
'server' => \yii\helpers\Url::to('/dmdfile/upload/image'),
'uploadFieldName' => 'upfile'
/*---end 非截图---*/
/*微信端单图非截图上传*/
'server' => \yii\helpers\Url::to('/dmdfile/upload/imagewechat'),//微信图片的传入的内容都是base64的,如果重写上传功能请按base64来获取内容并存储
'platform' => 'wechat',//必须的,微信端必须要有要不然完蛋了
'fileNumLimit' => 1//设置多图上传时候的最大上传文件数目,不用设置默认就是1
/*---end---*/
],
],
/* 截图的设置如下:*/
'screenshot' => true,
'server' => \yii\helpers\Url::to('/dmdfile/upload/imagestream'),
/*微信端截图*/
'screenshot' => true,//微信端也是可以截图的
'server' => \yii\helpers\Url::to('/dmdfile/upload/imagewechat'),//保持
'platform' => 'wechat',//微信端必须要有要不然完蛋了
'fileNumLimit' => 1
'imageList' => [
'type' => 'widget',
'class'=>\dmdedu\FileInput::className(),
'clientOptions'=>[
'accept' => [
'extensions' => 'gif,jpg,jpeg,bmp,png',
'mimeTypes' => 'image/gif,image/jpg,image/jpeg,image/bmp,image/png'//不要用image/* 会造成打开选择文件很卡
],
'pick' => [
'multiple' => true,//将多图模式打开
],
/*正常电脑端上传多图*/
'server' => \yii\helpers\Url::to('/dmdfile/upload/image'),//文件上传服务器处理的路径
'uploadFieldName' => 'upfile'//在前端存放文件的字段名
/*----end:电脑端多图上传----*/
/*微信端多图上传*/
'server' => \yii\helpers\Url::to('/dmdfile/upload/imagewechat'),//保持
'platform' => 'wechat',//微信端必须要有要不然完蛋了
'fileNumLimit' => 6//设置多图上传时候的最大上传文件数目,可选区间1-9的整数
/*---end: 微信端多图上传----*/
],
]
// 错误时
{"code": 1, "msg": "error"}
// 正确时, 其中 attachment 指的是保存在数据库中的路径,url 是该图片在web可访问的地址。。。。这里还没修整
{"code": 0, "url": "http://domain/图片地址", "attachment": "图片地址"}