PHP code example of bailangzhan / yii2-webuploader

1. Go to this page and download the library: Download bailangzhan/yii2-webuploader 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/ */

    

bailangzhan / yii2-webuploader example snippets


// 图片服务器的域名设置,拼接保存在数据库中的相对地址,可通过web进行展示
'domain' => 'http://blog.m/',
'webuploader' => [
	// 后端处理图片的地址,value 是相对的地址
	'uploadUrl' => 'blog/upload',
	// 多文件分隔符
	'delimiter' => ',',
	// 基本配置
	'baseConfig' => [
		'defaultImage' => 'http://img1.imgtn.bdimg.com/it/u=2056478505,162569476&fm=26&gp=0.jpg',
		'disableGlobalDnd' => true,
		'accept' => [
			'title' => 'Images',
			'extensions' => 'gif,jpg,jpeg,bmp,png',
			'mimeTypes' => 'image/*',
		],
		'pick' => [
			'multiple' => false,
		],
	],
],

 
// ActiveForm
echo $form->field($model, 'file')->widget('manks\FileInput', [
]); 

// 非 ActiveForm
echo '<label class="control-label">图片</label>';
echo \manks\FileInput::widget([
    'model' => $model,
    'attribute' => 'file',
]);

 
// ActiveForm
echo $form->field($model, 'file2')->widget('manks\FileInput', [
	'clientOptions' => [
		'pick' => [
			'multiple' => true,
		],
		// 'server' => Url::to('upload/u2'),
		// 'accept' => [
		// 	'extensions' => 'png',
		// ],
	],
]); 

// 错误时
{"code": 1, "msg": "error"}

// 正确时, 其中 attachment 指的是保存在数据库中的路径,url 是该图片在web可访问的地址
{"code": 0, "url": "http://domain/图片地址", "attachment": "图片地址"}

$ php composer.phar