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