How to upload and preview images by combining thinkphp5 and Layui (code)

不言
Release: 2023-04-03 19:36:01
Original
3445 people have browsed it

The content of this article is about how to implement image uploading and previewing (code) using the combination of thinkphp5 and Layui. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

html code

Copy after login

js code

var uploadInst = upload.render({ elem:'#cover' ,url:'addCourse' ,accept:'file' // 允许上传的文件类型 ,auto:true // 自动上传 ,before:function (obj) { console.log(obj); // 预览 obj.preview(function(index,file,result) { // console.log(file.name); //图片名字 // console.log(file.type); //图片格式 // console.log(file.size); //图片大小 // console.log(result); //图片地址 $('#preview').attr('src',result); //图片链接 base64 }); // layer.load(); } // 上传成功回调 ,done:function(res) { // console.log(upload); console.log(res); } // 上传失败回调 ,error:function(index,upload) { // 上传失败 } });
Copy after login

php interface

$file = request()->file('file'); // 移动到框架应用根目录/public/uploads/ 目录下 $info = $file->move('public/upload/'); if ($info) { $path = 'public/upload/'.$info->getSaveName(); return return_succ($path); }
Copy after login

Related recommendations:

PHP - image upload html upload image code image upload plug-in php php upload image code

Simple implementation of PHP ajax image upload mvc ajax upload image jquery ajax upload image php ajax upload image

The above is the detailed content of How to upload and preview images by combining thinkphp5 and Layui (code). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!