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