Skip to content
This repository was archived by the owner on Jul 9, 2023. It is now read-only.

Commit eab6acf

Browse files
committed
first commit
0 parents  commit eab6acf

File tree

13 files changed

+1056
-0
lines changed

13 files changed

+1056
-0
lines changed

README.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
## Laravel File Manager
2+
3+
### Installation:
4+
```
5+
composer require serjik/laravel-file-manger
6+
```
7+
8+
You must add the service provider to `config/app.php`
9+
``` php
10+
'providers' => [
11+
// for laravel 5.8 and below
12+
\Serjik\FileManager\FileManagerServiceProvider::class,
13+
];
14+
```
15+
16+
**Publish your config file and migrations**
17+
18+
```
19+
php artisan vendor:publish
20+
```
21+
<hr>
22+
23+
### Config:
24+
> config/filemanager.php
25+
``` php
26+
return [
27+
"type" => "default",
28+
29+
"types" => [
30+
"default" => [
31+
"provider" => \Serjik\FileManager\Types\File::class,
32+
"path" => "default_files/test/",
33+
"private" => false,
34+
"date_time_prefix" => true,
35+
"use_file_name_to_upload" => false,
36+
"secret" => "ashkdsjka#sdkdjfsj22188455$$#$%dsDFsdf",
37+
"download_link_expire" => 160, // minutes
38+
],
39+
// we add another types
40+
// "image" => [
41+
// //
42+
// ],
43+
],
44+
];
45+
```
46+
47+
### Config Parameters
48+
49+
50+
| name | type | description |
51+
|---------------|--------------|---------------------------|
52+
| provider | `string (class name)`| provider class name, must be extended of `Serjik\FileManager\BaseType` |
53+
|path | `string` | file upload path |
54+
|private | `boolean` | is private or no if is `true` so upload file in storage folder else if is `false` so upload file in public folder |
55+
|date_time_prefix|`boolean` | if is `true` so upload file with `/{year}/{month}/{day}` prefix|
56+
|use_file_name_to_upload| `boolean`| if is `true` we use of the file original name else we generate a random name|
57+
|secret |`string` | secret key for generate download link and download file|
58+
|download_link_expire|`boolean`|generated download link expire time|
59+
60+
61+
62+
## Lets start to use:
63+
64+
#### Upload a file:
65+
```php
66+
$file = request()->file('filename');
67+
$upload = File::upload($file);
68+
69+
// get file uploaded path
70+
$filePath = $upload->getFilePath();
71+
72+
// get file name
73+
$fileName = $upload->getName();
74+
```
75+
76+
#### You can use of this methods:
77+
78+
| method |description |
79+
|--------------------------------------|---------------------------------------------|
80+
| `useFileNameToUpload($status = true)`|if is `true` we use of the file original name else we generate a random name|
81+
|`getFile($name = null)` |get file by name and return a `\Serjik\FileManager\Models\File`|
82+
| `setPath($path)` |set file upload path |
83+
| `getUploadPath()` |get upload path |
84+
| `dateTimePrefix($value = true)` |if is `true` so upload file with `/{year}/{month}/{day}` prefix|
85+
| `setName(string $name)` |set file name |
86+
| `setFormat(string $format)` |set format for file upload |
87+
| `isPrivate()` | if you call this so upload file in storage folder and your you don't have permission to access this file|
88+
| `isPublic()` |if you call this so upload file in public folder and has access to this file|
89+
90+
91+
### Examples:
92+
```php
93+
$file = request()->file('filename');
94+
$upload = File::setName('your specific name')
95+
->isPrivate()
96+
->setFormat('png')
97+
->dateTimePrefix()
98+
->upload($file);
99+
// get file uploaded path => if is public you can use it for download
100+
dd($upload->getFilePath());
101+
```
102+
```php
103+
$file = File::getFile("file uploaded name");
104+
$file->name;
105+
$file->path;
106+
$file->type; // config file selected type
107+
$file->isPrivate;
108+
$file->isPublic;
109+
$file->generateLink();
110+
111+
// return response download
112+
// $file->download();
113+
```

composer.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "serjik/laravel-file-manger",
3+
"description": "Upload file and download it :)",
4+
"type": "library",
5+
"require": {
6+
"php": "^7.2",
7+
"laravel/framework": "^6.2"
8+
},
9+
"keywords": [
10+
"file",
11+
"file manager",
12+
"php file manager",
13+
"laravel file manager",
14+
"laravel"
15+
],
16+
"homepage": "https://github.com/AliGhaleyan/laravel-file-manager",
17+
"authors": [
18+
{
19+
"name": "AliGhaleyan",
20+
"email": "alighalehban1379@gmail.com"
21+
}
22+
],
23+
"autoload": {
24+
"psr-4": {
25+
"Serjik\\FileManager\\": "src/"
26+
},
27+
"files": [
28+
"src/helper.php"
29+
]
30+
}
31+
}

config/filemanager.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
return [
4+
"type" => "default",
5+
6+
"types" => [
7+
"default" => [
8+
"provider" => \Serjik\FileManager\src\Types\File::class,
9+
"path" => "default_files/test/",
10+
"private" => false,
11+
"date_time_prefix" => true,
12+
"use_file_name_to_upload" => false,
13+
"secret" => "ashkdsjka#sdkdjfsj22188455$$#$%dsDFsdf",
14+
"download_link_expire" => 160, // minutes
15+
],
16+
// "image" => [
17+
// //
18+
// ],
19+
],
20+
];

0 commit comments

Comments
 (0)