@@ -8,17 +8,17 @@ Laravel File API is good way to handle files with Laravel Storage.
8
8
9
9
1 . Install File API
10
10
11
- composer require unisharp/laravel-fileapi
11
+ composer require unisharp/laravel-fileapi
12
12
13
13
1 . Set service provider in ` config/app.php `
14
14
15
15
``` php
16
- Unisharp\FileApi\FileApiServiceProvider::class,
16
+ Unisharp\FileApi\FileApiServiceProvider::class,
17
17
```
18
18
19
19
1. publish config file
20
20
21
- php artisan vendor:publish --tag=fileapi_config
21
+ php artisan vendor:publish --tag=fileapi_config
22
22
23
23
### Config
24
24
@@ -27,79 +27,79 @@ in `config/fileapi.php`
27
27
1. fill in the storage path, which make routes for you.
28
28
29
29
```php
30
- 'path' => ['/images/event/', '/images/article/'],
30
+ 'path' => ['/images/event/', '/images/article/'],
31
31
```
32
32
33
33
it will generate routes like below :
34
34
35
35
```php
36
- Route::get('/images/event/{filename}', function ($filename) {
37
- $entry = new \Unisharp\FileApi\FileApi('/images/event/');
38
- return $entry->getResponse($filename);
39
- });
40
-
41
- Route::get('/images/article/{filename}', function ($filename) {
42
- $entry = new \Unisharp\FileApi\FileApi('/images/article/');
43
- return $entry->getResponse($filename);
44
- });
36
+ Route::get('/images/event/{filename}', function ($filename) {
37
+ $entry = new \Unisharp\FileApi\FileApi('/images/event/');
38
+ return $entry->getResponse($filename);
39
+ });
40
+
41
+ Route::get('/images/article/{filename}', function ($filename) {
42
+ $entry = new \Unisharp\FileApi\FileApi('/images/article/');
43
+ return $entry->getResponse($filename);
44
+ });
45
45
```
46
46
47
47
1. set default thumb sizes(by key and value)
48
48
49
49
```php
50
- 'default_thumbs' => ['S' => '96x96', 'M' => '256x256', 'L' => '480x480'],
50
+ 'default_thumbs' => ['S' => '96x96', 'M' => '256x256', 'L' => '480x480'],
51
51
```
52
52
53
53
### Initialize File API
54
54
55
- ```php
55
+ ```php
56
56
use \Unisharp\FileApi\FileApi;
57
57
58
58
$fa = new FileApi();
59
- ```
59
+ ```
60
60
61
61
or
62
62
63
- ``` php
63
+ ```php
64
64
$fa = new FileApi('/images/event/'); # initialize it by giving a base path
65
65
$fa_article = new FileApi('/images/article/'); # initiate another instance
66
- ```
66
+ ```
67
67
68
68
69
69
### Save to Storage By Giving Uploaded File
70
70
71
71
* Default Usage : get unique filename
72
72
73
73
```php
74
- $file = $fa->save(\Input::file('main_image')); // => wfj412.jpg
74
+ $file = $fa->save(\Input::file('main_image')); // => wfj412.jpg
75
75
```
76
76
77
77
* Custimize your upload file name
78
78
79
79
```php
80
- $file = $fa->save(\Input::file('main_image'), 'custimized_filename'); // => custimized_filename.jpg
80
+ $file = $fa->save(\Input::file('main_image'), 'custimized_filename'); // => custimized_filename.jpg
81
81
```
82
82
83
83
### Save thumbnails
84
84
85
85
* By default will set three thumbs(equal scaling)
86
86
87
87
```php
88
- $file = $fa->save(\Input::file('main_image'));
88
+ $file = $fa->save(\Input::file('main_image'));
89
89
```
90
90
91
91
* Set custom thumb sizes
92
92
93
93
```php
94
- $file = $fa
95
- ->thumbs(['S' => '150x100', 'M' => '300x200', 'L' => '450x300'])
96
- ->save(\Input::file('main_image'));
94
+ $file = $fa
95
+ ->thumbs(['S' => '150x100', 'M' => '300x200', 'L' => '450x300'])
96
+ ->save(\Input::file('main_image'));
97
97
```
98
98
99
99
* make cropped thumbs
100
100
101
101
```php
102
- $file = $fa->crop()->save(\Input::file('main_image'));
102
+ $file = $fa->crop()->save(\Input::file('main_image'));
103
103
```
104
104
105
105
### Get file fullpath (abstract path from Laravel Storage)
@@ -121,17 +121,17 @@ you can use url() method to get it
121
121
* Get file content
122
122
123
123
``` php
124
- \Storage::get($fa->getPath('wfj412.jpg'));
124
+ \Storage::get($fa->getPath('wfj412.jpg'));
125
125
```
126
126
127
127
* Write files
128
128
129
129
```php
130
- \Storage::put($fa->getPath('wfj412.jpg'));
130
+ \Storage::put($fa->getPath('wfj412.jpg'));
131
131
```
132
132
133
133
* Get Mime Type
134
134
135
135
```php
136
- \Storage::mimeType($fa->getPath('wfj412.jpg'));
136
+ \Storage::mimeType($fa->getPath('wfj412.jpg'));
137
137
```
0 commit comments