Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does laravel realize the interface of uploading pictures and set up soft links to access pictures?

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces laravel how to achieve the interface to upload pictures and establish soft links to access pictures of the relevant knowledge, the content is detailed and easy to understand, simple and fast operation, with a certain reference value, I believe that after reading this laravel how to achieve the interface to upload pictures and establish a soft link to access picture articles will have a harvest, let's take a look.

We also upload the nickname at the same time. The picture is saved in the resource table, and it is convenient to upload the associated id; in userProfile using laravel.

But you can't access it directly, so you need to establish a soft link:

PHP artisan storage:link

Executing this command will generate a folder in public to store the pictures, which can be accessed by address

Public function uploadAvatar (Request $request) {$validator = Validator::make ($request- > all (), ['nickname' = >' required | string | max:8', 'avatar' = >' required',]); if ($validator- > fails ()) {return $this- > responseForJson (ERR_ACCESS_DENID, $validator- > errors ());} $user_id=Auth::id (); $avatar = $request- > file ('avatar')-> store (' / public/'.date ('YmMurd'). / avatars') $avatar = Storage::url ($avatar); $resource=Resource::insertGetId (['type'= > 1 minted resourceful = > $avatar]); $Data= [' user_id'= > $user_id,'avatar'= > $resource,'nickname'= > $request- > nickname]; try {$edit = UserProfile::where ('user_id',$user_id)-> update ($Data); if ($edit) {return $this- > responseForJson (ERR_OK,' upload success');} return $this- > responseForJson (ERR_CREATE, 'upload fail') } catch (\ Exception $exception) {return $this- > responseForJson (ERR_ACCESS_DENID, $exception- > getMessage ());}} this is the end of the article on "how laravel implements the interface for uploading pictures and sets up soft links to access pictures". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "laravel how to upload pictures and establish soft links to access pictures". If you want to learn more, you are welcome to follow the industry information channel.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report