laravel5.6 upload images and display

Source: Internet
Author: User

Learn about the Great God Blog: 80105099
Document: laravel5.6 Document File transfer

Create a new file admin.php under config to define the path of the uploaded file

' Upload_img_path '                       = ' app/public/img ',//local upload image path ' upload_file_path '                       = ' app/public/files ' //local upload file path

Defined under the config/filesystems.php

' Disks ' = [    ' uploadimg ' =>[        ' driver ' + ' local ',        ' root ' =>storage_path (config (' admin.upload _img_path ')    ],    ' uploadfiles ' =>[        ' driver ' = ' local ',        ' root ' =>storage_path (config (' Admin.upload_file_path ')    ],    ' local ' = = [        ' driver ' + ' local ',        ' root ' = Storage_path (' App '),    ],    ' public ' = [        ' driver ' = ' local ',        ' root ' = ' storage_path ' (' app/public '),        ' url ' = env (' App_url '). ' /storage ',        ' visibility ' = ' public ', '    ,    ' s3 ' and ' =        ' driver ' = ' S3 ',        ' key ' and env ( ' Aws_key '),        ' secret ' = env (' Aws_secret '),        ' region ' = ' env ' (' aws_region '),        ' bucket ' = ' env ' (' Aws_bucket '),    ],

front-end display

{{html ()->form (' POST ', Route (' Frontend.repair.repair.upload '))
->attribute (' enctype ', ' Multipart/form-data ')->attribute (' Files ', ' ture ')->class (' Form-horizontal ')->open ()}}
(It is important to mark in red)
Controller in
Use Illuminate\support\facades\storage;

Public function sendmsg (sendmsgrequest $request)
{
$file = $request->file (' cover ');

//Save picture begin
$rule = [' jpg ', ' png ', ' gif '];
if ($request->hasfile (' cover ')) {//verify uploading pictures
$clientName = $file->getclientoriginalname ();//File formerly known as
$tmpName = $file->getfilename ();
$realPath = $file->getrealpath ();//absolute path to temporary files
$entension = $file->getclientoriginalextension ();//Extension
if (!in_array ($entension, $rule)) {
return ' picture format is Jpg,png,gif ';
}
$newName = MD5 (Date ("Y-m-d h:i:s"). $clientName). "." . $entension;//Image Rename
$bool = Storage::d ISK (' uploadimg ')->put ($newName, file_get_contents ($realPath));//Save Picture
//return back ();
//return Json_encode ([' Status ' = 1, ' filepath ' + $newName]);
} else {
$idCardFrontImg = ";
//return Json_encode ($IDCARDFRONTIMG);
$newName =1;
}

//Save picture End
}
Composer installs three items according to the requirements in the documentation.

when displayed:
<th></th><!--display pictures based on the name of the image stored in the database-

laravel5.6 upload images and display

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.