Laravel uploads files to Qiniu Cloud Storage-PHP source code

Source: Internet
Author: User
Laravel uploads files to Qiniu Cloud Storage
Public function store (Request $ request) {$ file = $ request-> file ('photo'); if (! $ File-> isValid () {return back () ;}// enter your Access Key and Secret Key $ accessKey = 'cifdxnihyc5wljfqtgzcft8dqy01a-xyFLyr71b '; $ secretKey = 'kbbk5jbf-G45QxWZza3H6zC_cl82vrMpa7f _ QEQ '; // Construct an authentication object $ auth = new Auth ($ accessKey, $ secretKey ); // the space to be uploaded $ bucket = 'laravel'; // Generate the upload Token $ token = $ auth-> uploadToken ($ bucket ); // Local path of the file to be uploaded $ filePath = $ file-> getRealPath (); // file name saved after being uploaded to Qiniu $ key = time (). ran D (999,9999 ). ". jpg "; // initialize the UploadManager object and upload the file $ uploadMgr = new UploadManager (); // call the putFile method of UploadManager to upload the file list ($ ret, $ err) = $ uploadMgr-> putFile ($ token, $ key, $ filePath); echo "\ n ===> putFile result: \ n"; if ($ err! = Null) {var_dump ($ err);} else {$ photo =' http://ddd.clouddn.com/ '. $ Ret ['key']; var_dump ($ ret );}}

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.