Laravel Seven cow cloud upload photo demo
HTML file @extends (' Layouts.admin ') @section (' title ', ' upload file ') @section (' content ') <!--I am the main content start--> <ul class= "breadcrumb" style= "FONT-SIZE:16PX;" > <li><a href= "#" > Home </a></li> <li><a href= "{{URL (' Admin/files
/index ')} "> File management </a></li> <li class=" active "> upload file </li> </ul> <div class= "Row" > <div class= "col-md-2 col-md-offset-9" > <button type= "button" class= "btn btn-success" onclick= "Window.history.go (-1);"
> Return file list </button> </div> </div> <form class= "Form-horizontal" > {{Csrf_field ()}} <div class= ' Form-group ' > <label for= ' file_title ' class= ' col-s M-2 Control-label "> file title </label> <div class=" col-sm-6 "> <input type=" Text "Name=" File_title "class=" form-control "id=" file_title "placeholder=" please input file title "> </div> </div> <
Div class= "Form-group" > <label for= "file_path" class= "col-sm-2 control-label" > File thumbnails </label> <input class= "Form-conrol col-sm-6 uploadimg" type= "file" id= "File_path" > <div C lass= "col-sm-6" style= "margin-top:10px;"
> </div> </div> <div class= "Form-group" > <label for= "status" class= "Col-sm-2 control -label "> Status </label> <label class=" Radio-inline "> <input type=" Radio " Name= "status" value= "0" > Draft </label> <label class= "Radio-inliNe "> <input type=" Radio "name=" Status "value=" 1 "checked> release </label> </div> <div class= "Form-group" > <div class= "col-sm-offset-2 col-sm-1 0 "> <button type=" button "class=" btn btn-success btn-lg "onclick=" submitbtn (); " > Save </button> <button type= "button" class= "btn btn-warning btn-lg" style= "margin-left:30 px; "onclick=" Window.history.go (-1); " > Back </button> </div> </div> </form> <!--I am the main content end--> @endsection @section (' my-js ') <script> function submitbtn () {var file_title = $ ('
Input[name=file_title]. Val ();
var File_path = $ (' input[name=file_path] '). Val ();
if (File_title = = ") {layer.msg (' banner title cannot be empty ');
Return
} if (File_path = = ") { Layer.msg (' banner thumbnail cannot be empty ');
Return
var data = $ ('. Form-horizontal '). Serialize ();
$.ajax ({type: POST), url: "/admin/file/create", Data:data, DataType: ' json ', Cache:false, success:function (data) {if (data . Code = = 0) {Swal ({title:data.msg, Tex T: ', type: ' Success ', timer:1000, O
Nopen: () => {swal.showloading ();
}, OnClose: () => {location.href = '/admin/banner/index '; })}else{layer.msg (data
. msg); }
}
}); //Upload Picture $ ("#file_path"). Change (function () {layer.msg (' file crosses, please wait ... '), {sh
ADE: [0.3]});
var formData = new FormData ();
Formdata.append ("File", $ (' #file_path ') [0].files[0]);
Formdata.append ("_token", "{{Csrf_token ()}}");
$.ajax ({type: POST), url: "/admin/file/upload", Data:formdata, DataType: ' json ', Processdata:false, Contenttype:false, cache:f Alse, Success:function (data) {if (Data.code = 0) {LAYER.M
SG (' File upload succeeded ');
$ ('. File_path '). attr (' src ', data.src);
$ (' #banner_img '). Val (Data.data);
}
}
});
}); </script> @endsection
//server-side 1.composer require Itbdw/laravel-storage-qiniu 2. Edit config/app.php providers plus one line itbd W\qiniustorage\qiniufilesystemserviceprovider::class, 3. Edit config/filesystems.php, add ' qiniu ' => [' Driver ' => ' Qiniu ', ' domain ' => ' xxxxx.bkt.clouddn.com ',//Your seven beef domain name ' access_key ' => ', AccessKey ' Secret_key ' => ',//secretkey ' bucket ' => ',//bucket name, that is, seven cattle cloud storage empty Name], 4. Upload method Public Function upload () {$disk = \storage::d ISK (' Qiniu '); upload $time = Date (' y-m-with seven Cattle cloud ')
d '); $filename = $disk->put ($time, request ()->file (' file '))//upload if (! $filename) {return response ()->json ([' Co
De ' => 1, ' msg ' => ' upload failed ']); $img _url = $disk->getdriver ()->downloadurl ($filename);
Get Download Link return response ()->json ([' Code ' => 0, ' msg ' => ' uploaded success ', ' src ' => $img _url]); }