In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains the "ThinkPHP6 upload picture code demo is what", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "ThinkPHP6 upload picture code demo is what" it!
This article shows the ThinkPHP6 upload picture code demo, the code is available for testing.
HTML part code commodity picture selection picture JS part code $(document) .ready (function () {var input = $("# imgFile"); / / bind upload button to input ['file'] $("# uploadBtn") .click (function () {input.trigger ("click");}) Input.change (function () {/ / if value is not empty, call the file loading method if ($(this). Val ()! = ") {doUpload (this);}}); / / upload picture var SCOPE = {'uploadUrl':' {: url ("'+ urlPath +'/ upload ")}',} Function doUpload () {var formData = new FormData ($("# myform") [0]), appendDiv = $("# uploadImage"), imageUrl ='', imageDiv ='' Ajax ({url: SCOPE.uploadUrl, type: 'POST', data: formData, async: false, cache: false, contentType: false, processData: false, success: function (result) {if (result.status = 1) {appendDiv.empty (); imageUrl =' / storage/' + result.data ImageDiv ='; appendDiv.append (imageDiv);}},});} upload method in ThinkPHP / * Image upload (ajax) * @ return\ think\ Response | void * @ throws\ Exception * / public function upload () {/ / get the form upload file, for example, upload 001.jpg $file = request ()-> file ('imgFile') Try {/ / verify validate (['imgFile'= > [' fileSize' = > 410241024, 'fileExt' = >' jpg,jpeg,png,bmp,gif', 'fileMime' = >' image/jpeg,image/png,image/gif', / / this must be added, I think it's important! ])-> check (['imgFile' = > $file]); / / upload pictures to the local server $saveName =\ think\ facade\ Filesystem::disk (' public')-> putFile ('merchant', $file,' data'); $this- > result (1, 'picture uploaded successfully', $saveName, 'json') } catch (\ Exception $e) {/ / failed verification output error message return $this- > exceptionHandle ($e, 'picture upload failed!'. $e-> getMessage (), 'json',');}} Thank you for reading, this is the content of "what is the ThinkPHP6 upload picture code demo". After the study of this article, I believe you have a deeper understanding of what the ThinkPHP6 upload picture code demo is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.