


How to upload multiple images for instant display and instant deletion using PHP
This article mainly introduces the method of PHP to realize instant display and instant deletion of uploaded multiple images. It analyzes PHP's related operation skills for previewing, uploading and deleting image files in the form of examples. Friends in need can refer to the following
The example of this article describes the method of PHP to realize the instant display and instant deletion of uploaded multiple images. Share it with everyone for your reference. The details are as follows:
Just like this, every time you select an image, it will be displayed immediately and attached to the right. You can also delete an element at will. .
In fact, when the onchange event of the input box of type=file ===》》》post data is submitted to the hidden ifram (target specification of the form form) ===》》》post data is received Directly echo the script tag to return data to the front-end page and assign a value, and then store the image path using hidden fields:
HTML:
<!doctype html> <html lang="cn"> <include file="Public/head"/> <body> <include file="Public/nav"/> <iframe name="upload_url" style="display:none"></iframe> <p class="wlog"> <p class="wlog_t cf"> <b>写日志</b> </p> <p class="wlog_c"> <form class="cf" id="myform" target="" enctype="multipart/form-data" action="" method="post"> <p class="wlog_l"> <textarea id="content" name="data[content]"></textarea> <input type="hidden" id="step" value="1" name="data[step]" /> </p> <p class="wlog_r"> <h2>选择装修阶段</h2> <b class="cur" mine="1" style="line-height:20px;">准备开工</b> <b mine="2" >水电</b> <b mine="3">泥木</b> <b mine="4">油漆</b> <b mine="5">竣工</b> <b mine="6">软装</b> <!-- <input type="hidden" value="准备开工"> --> </p> <p class="wlog_f cf"> <h2><b>上传图片</b>选择装修过程中的照片,每张低于5M,支持JPG/JPEG/PNG格式,最多9张</h2> <p class="wlog_p cf"> <a href="javascript:;" rel="external nofollow" ><img src="__PUBLIC__/home/images/2016-10-29_231703.png" alt=""><input onchange="submitimg()" type="file" name="thumb"/></a> <p id="addimg"></p> <!-- <b><img src="__PUBLIC__/home/images/2016-10-18_094906.png" alt=""><i>x</i></b> <b><img src="__PUBLIC__/home/images/2016-10-18_094906.png" alt=""><i>x</i></b> <b><img src="__PUBLIC__/home/images/2016-10-18_094906.png" alt=""><i>x</i></b> <b><img src="__PUBLIC__/home/images/2016-10-18_094906.png" alt=""><i>x</i></b> <b><img src="__PUBLIC__/home/images/2016-10-18_094906.png" alt=""><i>x</i></b> <b><img src="__PUBLIC__/home/images/2016-10-18_094906.png" alt=""><i>x</i></b> <b><img src="__PUBLIC__/home/images/2016-10-18_094906.png" alt=""><i>x</i></b> <b><img src="__PUBLIC__/home/images/2016-10-18_094906.png" alt=""><i>x</i></b> --> </p> </p> <p class="wlog_sm"><input type="botton" onclick="return goods_form_submit()" readonly="readonly" value="发布日志"></p> </form> </p> </p> <include file="Public/footer"/> <script type="text/javascript"> function submitimg(){ $("#myform").attr('target','upload_url'); $("#myform").attr('action',"{:U('Journal/submitimg')}"); $("#myform").submit(); } function goods_form_submit() { if(!$('#content').val()){ alert('请填写日志'); return false; } $('#myform').attr('target',''); $('#myform').attr('action',''); $('#myform').submit(); } function callblack_img(path,uid) { var html=""; var dir = "{:C(FILE_PATH)}"; var html ='<b><img src='+dir+path+'><i>x</i><input type="hidden" value="'+path+'" name="thumb['+uid+']"></b>'; $('#addimg').append(html); } </script> <script type="text/javascript" src="__PUBLIC__/home/js/jquery-1.10.1.min.js"></script> <script type="text/javascript" src="__PUBLIC__/home/js/basis.js"></script> <script> $(function(){ $('.wlog_r b').click(function(event) { $(this).addClass('cur').siblings('b').removeClass('cur'); $('.wlog_r input[type=hidden]').val($(this).text()); }); $("#addimg").delegate("i","click",function () { $(this).parent("b").remove(); }) }) $("b").click(function(){ var value =$(this).attr('mine'); $("#step").val(value); }) </script> </body> </html>
Controller(returns the path of the selected image (already uploaded) in the server):
public function submitimg(){ if(IS_POST){ $data = I('post.data');//获取post数据 $res = fab_upload($_FILES);//上传文件 $uid=uniqid(); $res=$res['thumb']; if($res){ echo "<script>parent.callblack_img('{$res}','{$uid}');</script>"; } } }
The real function that finally receives the form data and stores it in the database:
public function add_journal(){ if(IS_POST){ var_dump($_POST);die; }else{ $this->display(); } }
Related recommendations:
jquery - php Upload multiple picturesDescribe each picture after the picture and save it to mysql
The above is the detailed content of How to upload multiple images for instant display and instant deletion using PHP. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.
