thinkphp image How to delete images: 1. Open the front-end code file; 2. Use the Ajax code "success:function(data) {...}" to achieve partial refresh; 3. Open the tp back-end code file , and delete the image data through the "public function delete_image(){...}" method.
The operating environment of this tutorial: Windows 7 system, ThinkPHP version 5, Dell G3 computer.
thinkphp imageHow to delete pictures?
ThinkPHP5 uses ajax to asynchronously delete images
I have been writing code for a year or two, and I have some experience. Typing code is always a tiring job. It’s not so easy to stand on other people’s shoulders and fix the wheel. That’s all, let’s continue repairing the wheels.
The biggest advantage of AJAX is that it can exchange data with the server and update part of the web page content without reloading the entire page.
ThinkPHP5 uses ajax to asynchronously delete images. The entire page address remains unchanged and partial refresh is achieved.
Code display:
<script type="text/javascript"> function delete_image(o){ if(!confirm('确定删除图片?')){ return false; } var url="{:url('delete_image')}"; var imgsrc=$(o).attr('id'); $.ajax({ url : url, type : "post", dataType : "json", data : { imgsrc:imgsrc }, //如果返回成功 success : function(data) { if(data.type == 1){ //执行删除操作 $(o).remove(); alert('删除成功!'); }else if(data.type == 2){ alert('删除失败!'); }else{ alert('删除失败!'); } } }); } </script>
Submit to the background method:
public function delete_image(){ //接收获取的值 $imgsrc = input('imgsrc'); //拼接链接地址 $imgsrc = DEL_UEDITOR.$imgsrc; if(file_exists($imgsrc)){ if(@unlink($imgsrc)){ //删除成功 echo json_encode(array('type' => 1)); }else{ //删除失败 echo json_encode(array('type' => 2)); } }else{ //如果不存在,删除失败 echo json_encode(array('type' => 3)); } }
Click the delete button and a pop-up box will be displayed to prompt whether the deletion is successful or failed. !
Recommended learning: "thinkPHP Video Tutorial"
The above is the detailed content of How to delete pictures in thinkphp image. For more information, please follow other related articles on the PHP Chinese website!

The article discusses ThinkPHP's built-in testing framework, highlighting its key features like unit and integration testing, and how it enhances application reliability through early bug detection and improved code quality.

Article discusses using ThinkPHP for real-time stock market data feeds, focusing on setup, data accuracy, optimization, and security measures.

The article discusses key considerations for using ThinkPHP in serverless architectures, focusing on performance optimization, stateless design, and security. It highlights benefits like cost efficiency and scalability, but also addresses challenges

The article discusses implementing service discovery and load balancing in ThinkPHP microservices, focusing on setup, best practices, integration methods, and recommended tools.[159 characters]

ThinkPHP's IoC container offers advanced features like lazy loading, contextual binding, and method injection for efficient dependency management in PHP apps.Character count: 159

The article discusses using ThinkPHP to build real-time collaboration tools, focusing on setup, WebSocket integration, and security best practices.

ThinkPHP benefits SaaS apps with its lightweight design, MVC architecture, and extensibility. It enhances scalability, speeds development, and improves security through various features.

The article outlines building a distributed task queue system using ThinkPHP and RabbitMQ, focusing on installation, configuration, task management, and scalability. Key issues include ensuring high availability, avoiding common pitfalls like imprope


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

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

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.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment