Integrate Qiniu Cloud storage in Laravel5 for cloud storage

Source: Internet
Author: User
Integration of Qiniu Cloud storage in Laravel5 realize cloud storage function this expansion package is based on https://github.com/qiniu/php-sdk development, is Qiniu Cloud storage Laravel 5Storage version, with this expansion package, you can integrate Qiniu Cloud storage in Laravel 5.

1. install and configure

Before using it, install it through Composer:

composer require zgldh/qiniu-laravel-storage

Then register the service provider in config/app. php:

zgldh\QiniuStorage\QiniuFilesystemServiceProvider::class

Next, add the following options to disks in config/filesystems. php:

'Disk' => [..., 'qiniu '=> ['driver' => 'qiniu ', 'domains' => ['default' => 'laravelemy Emy .com1.z0.glb.clouddn.com ', // your Qiniu domain name 'https' => 'dn-laravelacademy. qbox. me ', // your HTTPS domain name 'custom' => 'static .laravelacademy.org', // your custom domain name], 'Access _ key' => '', // AccessKey 'secret _ key' => '', // SecretKey 'bucket' =>'', // bucket name 'Your y _ url' => '', // persistent processing callback address],],
2. use

First usage:

$ Disk = \ Storage: disk ('qiniu '); $ disk-> exists('file.jpg'); // check whether the file exists $ disk-> get('file.jpg '); // get the file content $ disk-> put('file.jpg ', $ contents); // upload the file $ disk-> prepend ('File. log', 'prepended text'); // add the content to the beginning of the file $ disk-> append ('File. log', 'appended text'); // add content to the end of the file $ disk-> delete('file.jpg '); // delete the file $ disk-> delete('file1.jpg', 'file2.jpg ']); $ disk-> copy ('Old/file1.jpg ', 'New/file1.jpg'); // copy the file to the new path $ disk-> move ('Old/ File1.jpg ', 'New/file1.jpg'); // move the file to the new path $ size = $ disk-> size('file1.jpg '); // get the file size $ time = $ disk-> lastModified('file1.jpg '); // Get the latest modification time (UNIX) $ files = $ disk-> files ($ directory ); // get all files in the directory $ files = $ disk-> allFiles ($ directory); // This is not implemented... $ Directories = $ disk-> directories ($ directory); // This is not implemented either... $ Directories = $ disk-> allDirectories ($ directory); // This is not implemented either... $ Disk-> makeDirectory ($ directory); // This actually has no function $ disk-> deleteDirectory ($ directory); // delete the directory, including all sub-file subdirectories in the directory $ disk-> getDriver ()-> uploadToken('file.jpg '); // Obtain the uploaded Token $ disk-> getDriver ()-> downloadUrl('file.jpg '); // Obtain $ disk-> getDriver ()-> downloadUrl('file.jpg ', 'https'); // Obtain https $ disk-> getDriver ()-> privateDownloadUrl('file.jpg '); // get private bucket $ disk-> getDriver ()-> privateDownloadUrl('file.jpg ', 'https'); // Obtain Private B Ucket HTTPS $ disk-> getDriver ()-> imageInfo('file.jpg '); // Obtain image information $ disk-> getDriver ()-> imageExif('file.jpg '); // Obtain Image EXIF information $ disk-> getDriver ()-> imagePreviewUrl('file.jpg ', 'imageview2/0/w/100/h/100 '); // Obtain the image preview URL $ disk-> getDriver ()-> persistentFop ('File. flv', 'avthumb/m3u8/segtime/40/vcodec/libx264/s/320x240 '); // execute persistent data processing $ disk-> getDriver () -> persistentFop ('File. flv', 'fop', 'queue name'); // use a private queue to perform persistent data processing $ disk-> getD River ()-> persistentStatus ($ persistent_fop_id); // view the state of persistent data processing.

The second usage (that is, a getDriver is omitted ):

Use zgldh \ QiniuStorage; $ disk = QiniuStorage: disk ('qiniu '); $ disk-> exists('file.jpg '); // check whether the file exists $ disk-> get('file.jpg '); // Obtain the file content $ disk-> put('file.jpg', $ contents ); // upload the file $ disk-> prepend ('File. log', 'prepended text'); // add the content to the beginning of the file $ disk-> append ('File. log', 'appended text'); // add content to the end of the file $ disk-> delete('file.jpg '); // delete the file $ disk-> delete('file1.jpg', 'file2.jpg ']); $ disk-> copy ('Old/file1.jpg ', 'New/f Ile1.jpg '); // copy the file to the new path $ disk-> move ('Old/file1.jpg', 'New/file1.jpg '); // move the file to the new path $ size = $ disk-> size('file1.jpg '); // Obtain the file size $ time = $ disk-> lastModified('file1.jpg '); // obtain the latest modification time (UNIX) $ files = $ disk-> files ($ directory ); // get all files in the directory $ files = $ disk-> allFiles ($ directory); // This is not implemented... $ Directories = $ disk-> directories ($ directory); // This is not implemented either... $ Directories = $ disk-> allDirectories ($ directory); // This is not implemented either... $ Disk-> makeDirectory ($ directory); // This actually has no function $ disk-> deleteDirectory ($ directory); // delete the directory, including all sub-file subdirectories in the directory $ disk-> uploadToken('file.jpg '); // Get the upload Token $ disk-> downloadUrl('file.jpg'); // Get $ disk-> downloadUrl('file.jpg ', 'https'); // Obtain https $ disk-> privateDownloadUrl('file.jpg '); // obtain private bucket $ disk-> privateDownloadUrl('file.jpg', 'https '); // Obtain the HTTPS $ disk-> imageInfo('file.jpg ') of the private bucket; // Obtain the image information $ disk-> imageExi F('file.jpg '); // Obtain the Image EXIF information $ disk-> imagePreviewUrl('file.jpg', 'imageview2/0/w/100/h/100 '); // Obtain the image preview URL $ disk-> persistentFop ('File. flv', 'avthumb/m3u8/segtime/40/vcodec/libx264/s/320x240 '); // execute persistent data processing $ disk-> persistentFop ('File. flv', 'fop', 'queue name'); // use a private queue to perform persistent data processing $ disk-> persistentStatus ($ persistent_fop_id); // view the status of persistent data processing.
3. References

This extension package GitHub address for https://github.com/zgldh/qiniu-laravel-storage, based on https://github.com/qiniu/php-sdk development, for more details, please refer to seven cattle official php sdk User Guide: http://developer.qiniu.com/code/v7/sdk/php.html

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.