下面是update_form中的kartik文件输入小部件。
echo FileInput::widget(
[
'name' => 'BriefRequirements[requirement_value][]',
'attribute' => 'assets_file',
'id' => 'assets_file',
'options' => ['multiple' => true],
'pluginOptions' => [
'overwriteInitial' => false,
'initialPreview' => $image_url,
'deleteUrl' => ' site/delete',
'initialPreviewAsData' => true,
'initialPreviewFileType' => 'image' //'pdf'
]
]
);
下面是多个图像加载代码,
foreach ($modelRequirements as $req) {
$image_url[] = Yii::$app->request->baseUrl
. '/theme/business_campaign_files/'
. $req['requirement_value'];
}
我的两个问题需要帮助:
'initialPreviewFileType'=>'any'
]不工作。'deleteUrl' => ' site/delete'
,'id'=>12
,在下面的代码中,我得到了两个问题的结果。
$initializeConfig = [];
$initializeConfig1 = [];
if ($modelRequirements) {
foreach ($modelRequirements as $req) {
$extension = substr(
$req['requirement_value'],
strrpos($req['requirement_value'], '.') + 1
);
$image_url[] = Yii::$app->request->baseUrl
. '/theme/business_campaign_files/'
. $req['requirement_value'];
$initializeConfig1['url'] = Url::toRoute('delete-requirement');
$initializeConfig1['key'] = $req['id'];
$initializeConfig1['type'] = $type;
array_push($initializeConfig, $initializeConfig1);
}
}
在上面的代码中,我得到了两个问题的结果。
$initializeConfig1['type'] = $type;
一样发送我得到基于扩展名的图像扩展我正在设置文件like[pdf,xlsx,image]
的格式。easyOne
各种方法来管理您的预览。此示例演示了以下功能:对于单个图像,您可以使其与“多个相同”
$files = array();
$files['initialPreview'] = Url::base(TRUE) . '/' . $uploadurl . $newFileName;
$files['initialPreviewAsData'] = true;
//FOR PDF
if ($fieldtype == 'pdf') {
$files['initialPreviewConfig'][] = array('type' => 'pdf', 'key' => $newFileName);
} else {
//FOR IMAGES
$files['initialPreviewConfig']['key'] = $newFileName;
}
$files['namefile'] = $newFileName;
JSON响应:
{
"initialPreview": "http://localhost/yii2/uploads/project/brochure/fileone.pdf",
"initialPreviewAsData": true,
"initialPreviewConfig": [
{
"type": "pdf",
"key": "fileone.pdf"
}
],
"namefile": "fileone.pdf"
}