search
Homephp教程PHP开发Yii2 framework study notes (8)
Yii2 framework study notes (8)Dec 30, 2016 am 10:20 AM

jquery-file-upload (http://blueimp.github.io/jQuery-File-Upload/) is an excellent file ajax upload plug-in that supports multiple selection, preview, concurrent upload, etc.

jquery-file-upload already has a ready-made yii2 plug-in (https://github.com/2amigos/yii2-file-upload-widget), and composer is also used for installation.

Add "2amigos/yii2-file-upload-widget": "~1.0" to composer.json, and then run composer update

This plug-in only provides the function of front-end display (front-end The implementation also has some flaws (mentioned below). The background processing code is not provided, and there are no examples. You need to explore it yourself.

Copy and paste the code in the front-end usage example directly.

<?php

// with UI

use dosamigos\fileupload\FileUploadUI;
?>
<?= FileUploadUI::widget([
    &#39;model&#39; => $model,
    &#39;attribute&#39; => &#39;image&#39;,
    &#39;url&#39; => [&#39;media/upload&#39;, &#39;id&#39; => $tour_id],
    &#39;gallery&#39; => false,
    &#39;fieldOptions&#39; => [
            &#39;accept&#39; => &#39;image/*&#39;
    ],
    &#39;clientOptions&#39; => [
            &#39;maxFileSize&#39; => 2000000
    ],
    // ...
    &#39;clientEvents&#39; => [
            &#39;fileuploaddone&#39; => &#39;function(e, data) {
                                    console.log(e);
                                    console.log(data);
                                }&#39;,
            &#39;fileuploadfail&#39; => &#39;function(e, data) {
                                    console.log(e);
                                    console.log(data);
                                }&#39;,
    ],
]);
?>

The interface is as follows

Yii2 framework study notes (8)

##According to the configuration inside, we need to create two new files, one ImageUploadModel.php, which contains the image field

class UploadImageForm extends Model {

	public $image;
	
	public function getImage() {
		return $this->image;
	}
	
	public function setImage($newOne) {
		$this->image = $newOne;
	}
}

A controller MediaController.php, including the actionUpload method

Yii2 framework study notes (8)

The content returned by the background should be based on the original plug-in documentation. There is no relevant information provided on the yii2 plug-in website.


Reference URL: https://github.com/blueimp/jQuery-File-Upload/wiki/Setup#using-jquery-file-upload-ui-version-with-a-custom-server-side -upload-handler

also needs to provide the actionDelete method, which is used to delete

Yii2 framework study notes (8)


and then do some custom functions . Add a textarea to the list item for entering picture notes, as shown in the figure.

Yii2 framework study notes (8)##You need to modify \yii2\vendor\2amigos\yii2-file-upload-widget\src\views\upload.php

This file is for each A single-line template, add a textarea

Yii2 framework study notes (8)Another problem encountered in actual application is that if multiple photos are selected at the same time and uploaded concurrently, all the photos received later will It is the picture in the first request, and the original picture cannot be uploaded.

It is suspected that the name of the file input is UploadImageForm[image], but it has not been confirmed. I hope you can tell me if you know.

The solution is to disable concurrent uploads and use the synchronous upload method, as shown above, add the 'sequentialUploads' => true option

The above is the content of Yii2 framework study notes (8), more For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Microsoft NET Framework 安装问题 错误代码 0x800c0006 修复Microsoft NET Framework 安装问题 错误代码 0x800c0006 修复May 05, 2023 pm 04:01 PM

.NETFramework4是开发人员和最终用户在Windows上运行最新版本的应用程序所必需的。但是,在下载安装.NETFramework4时,许多用户抱怨安装程序在中途停止,显示以下错误消息-“ .NETFramework4hasnotbeeninstalledbecauseDownloadfailedwitherrorcode0x800c0006 ”。在您的设备上安装.NETFramework4时,如果您也在体验它,那么您就来对了地方

如何在 Windows 11/10 上使用 SetupDiag 识别 Windows 升级问题如何在 Windows 11/10 上使用 SetupDiag 识别 Windows 升级问题Apr 17, 2023 am 10:07 AM

每当您的Windows11或Windows10PC出现升级或更新问题时,您通常会看到一个错误代码,指示故障背后的实际原因。但是,有时,升级或更新失败可能不会显示错误代码,这时就会出现混淆。有了方便的错误代码,您就可以确切地知道问题出在哪里,因此您可以尝试修复。但是由于没有出现错误代码,因此识别问题并解决它变得极具挑战性。这会占用您大量时间来简单地找出错误背后的原因。在这种情况下,您可以尝试使用Microsoft提供的名为SetupDiag的专用工具,该工具可帮助您轻松识别错误背后的真

SCNotification 已停止工作 [修复它的 5 个步骤]SCNotification 已停止工作 [修复它的 5 个步骤]May 17, 2023 pm 09:35 PM

作为Windows用户,您很可能会在每次启动计算机时遇到SCNotification已停止工作错误。SCNotification.exe是一个微软系统通知文件,由于权限错误和点网故障等原因,每次启动PC时都会崩溃。此错误也以其问题事件名称而闻名。因此,您可能不会将其视为SCNotification已停止工作,而是将其视为错误clr20r3。在本文中,我们将探讨您需要采取的所有步骤来修复SCNotification已停止工作,以免它再次困扰您。什么是SCNotification.e

Microsoft .NET Framework 4.5.2、4.6 和 4.6.1 将于 2022 年 4 月终止支持Microsoft .NET Framework 4.5.2、4.6 和 4.6.1 将于 2022 年 4 月终止支持Apr 17, 2023 pm 02:25 PM

已安装Microsoft.NET版本4.5.2、4.6或4.6.1的MicrosoftWindows用户如果希望Microsoft将来通过产品更新支持该框架,则必须安装较新版本的Microsoft框架。据微软称,这三个框架都将在2022年4月26日停止支持。支持日期结束后,产品将不会收到“安全修复或技术支持”。大多数家庭设备通过Windows更新保持最新。这些设备已经安装了较新版本的框架,例如.NETFramework4.8。未自动更新的设备可能

适用于 Windows 11 的KB5012643破坏了.NET Framework 3.5应用程序适用于 Windows 11 的KB5012643破坏了.NET Framework 3.5应用程序May 09, 2023 pm 01:07 PM

自我们谈论影响安装KB5012643forWindows11的用户的新安全模式错误以来已经过去了一周。这个讨厌的问题并没有出现在微软在发布当天发布的已知问题列表中,因此让所有人都感到意外。好吧,就在您认为情况不会变得更糟的时候,微软为安装此累积更新的用户投下了另一颗炸弹。Windows11Build22000.652导致更多问题因此,这家科技公司警告Windows11用户,他们在启动和使用某些.NETFramework3.5应用程序时可能会遇到问题。听起来很熟悉?不过请不要惊

yii2 怎么去掉jqueryyii2 怎么去掉jqueryFeb 17, 2023 am 09:55 AM

yii2去掉jquery的方法:1、编辑AppAsset.php文件,注释掉变量$depends里的“yii\web\YiiAsset”值;2、编辑main.php文件,在字段“components”下面添加配置为“'yii\web\JqueryAsset' => ['js' => [],'sourcePath' => null,],”即可去掉jquery脚本。

酷冷至尊携手Framework推出创新迷你机箱套件,兼容笔记本主板酷冷至尊携手Framework推出创新迷你机箱套件,兼容笔记本主板Dec 15, 2023 pm 05:35 PM

12月9日消息,最近,酷冷至尊在台北电脑展上的一次展示活动中,展示了与笔记本模块化方案提供商framework合作的迷你机箱套件,这个套件的独特之处在于,它可以兼容并安装来自framework笔记本的主板。目前,这款产品已经开始在市场上销售,售价定为39美元,按当前汇率折合大约279元人民币。这款机箱套件的型号被命名为“frameWORKMAINBOARDCASE”。在设计方面,它体现了极致的紧凑与实用性,尺寸仅为297x133x15毫米。它的设计初衷是为了能够无缝接入framework笔记本的

精选几道CTF习题,带你学习yii2框架!精选几道CTF习题,带你学习yii2框架!Feb 23, 2022 am 10:33 AM

本篇文章带大家了解yii2框架,分享几道CTF习题,通过它们来学习yii2框架,希望对大家有所帮助。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools