我正在使用个人资料更新功能,其中用户要显示多个图像,以便他可以添加新图像或删除旧图像,我正在使用js
库,通过该库显示预览,但是当我提交表单时,该数据中不存在旧图像。我可以将值推入文件输入字段,还是可以解决此问题,以便实现此功能。
Link to Library that I'm using
我的Js代码:
var upload = new FileUploadWithPreview('myUniqueUploadId', {
showDeleteButtonOnImages: true,
text: {
chooseFile: 'Įkelkite nuotrauką',
browse: 'naršyti',
selectedCount: 'Pasirinkti failai',
},
presetFiles: [
<?php
foreach($Workimages as $Workimg){
echo $website_url.'master_image/'.$Workimg.','
}?>
],
});
答案 0 :(得分:0)
您缺少引用图像路径的提示
var upload = new FileUploadWithPreview('myUniqueUploadId', {
showDeleteButtonOnImages: true,
text: {
chooseFile: 'Įkelkite nuotrauką',
browse: 'naršyti',
selectedCount: 'Pasirinkti failai',
},
presetFiles: [
<?php
foreach($Workimages as $Workimg){
echo '"'.$website_url.'master_image/'.$Workimg.'",'
}?>
],
});
更好的方法是使用json_encode数组
<?php
$Workimages = array_map(function($v) use($website_url) { return $website_url.'master_image/'.$Workimg; }, $Workimages);
?>
var upload = new FileUploadWithPreview('myUniqueUploadId', {
showDeleteButtonOnImages: true,
text: {
chooseFile: 'Įkelkite nuotrauką',
browse: 'naršyti',
selectedCount: 'Pasirinkti failai',
},
presetFiles: <?= json_encode($Workimages); >
});