Get the App
SLTechnology News&Howtos  ›  Development  › 

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

Shulou Source: shulou.com Published: 2022-06-01 02:29:47 10月03日 Update

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.

Tags: Pictures links interfaces knowledge content articles values can be passed at the same time commands addresses easy to operate files folders articles easy to understand nicknames more see industry Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology MySQL Microsoft NVidia Linux