Skip to content

Commit 07a2903

Browse files
update
1 parent a871f81 commit 07a2903

File tree

6 files changed

+76
-22
lines changed

6 files changed

+76
-22
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ $file = File::name('html_input_name');
180180
181181
$file->getMessage();
182182
183+
184+
// This will change the message text
183185
$file->getMessage('new Message');
184186
```
185187

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
],
1717
"require": {
1818
"php": ">=8.0",
19-
"tamedevelopers/support": "^4.0.5",
20-
"tamedevelopers/validator": "^5.0"
19+
"tamedevelopers/support": "*",
20+
"tamedevelopers/validator": "*"
2121
},
2222
"suggest": {
2323
"aws/aws-sdk-php": "Required to use Amazon `s3` composer require aws/aws-sdk-php (^3.282.0)."

src/File.php

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ public function size($size)
299299
*/
300300
public function limit($limit)
301301
{
302-
$this->config['limit'] = self::numbericToInt($limit) ?: 1;
302+
$this->config['limit'] = self::numericToInt($limit) ?: 1;
303303

304304
return $this;
305305
}
@@ -316,7 +316,7 @@ public function limit($limit)
316316
public function width($width, ?bool $actual = true)
317317
{
318318
$this->config['width'] = [
319-
'size' => self::numbericToInt($width),
319+
'size' => self::numericToInt($width),
320320
'actual' => $actual
321321
];
322322

@@ -335,7 +335,7 @@ public function width($width, ?bool $actual = true)
335335
public function height($height, ?bool $actual = true)
336336
{
337337
$this->config['height'] = [
338-
'size' => self::numbericToInt($height),
338+
'size' => self::numericToInt($height),
339339
'actual' => $actual
340340
];
341341

@@ -479,17 +479,17 @@ public function form()
479479
* Unlink File from Server
480480
*
481481
* @param string $pathToFile
482-
* - [base path will be automatically added]
482+
* - [full path to file is required]
483483
*
484-
* @param string|null $fileName
484+
* @param string|null $restrictedfileName
485485
* - [optional] file name. <avatar.png>
486486
* - File to check against before unlinking
487487
*
488488
* @return void
489489
*/
490-
static public function unlink(string $pathToFile, $fileName = null)
490+
static public function unlink(string $pathToFile, $restrictedfileName = null)
491491
{
492-
Tame::unlink($pathToFile, $fileName);
492+
Tame::unlink($pathToFile, $restrictedfileName);
493493
}
494494

495495
/**
@@ -503,6 +503,24 @@ public function echoJson(int $response = 0, $message = null)
503503
{
504504
return Tame::echoJson($response, $message);
505505
}
506+
507+
/**
508+
* Get Error Data
509+
* @return array
510+
*/
511+
public function getError()
512+
{
513+
return $this->error;
514+
}
515+
516+
/**
517+
* Get Config Data
518+
* @return array
519+
*/
520+
public function getConfig()
521+
{
522+
return $this->config;
523+
}
506524

507525
/**
508526
* Destructor for Removing Cloud Save Files

src/Methods/FileMethod.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ static protected function isArray($value = null)
191191
* @param mixed $value
192192
* @return mixed
193193
*/
194-
static protected function numbericToInt($value = null)
194+
static protected function numericToInt($value = null)
195195
{
196196
if(is_numeric($value)){
197197
$value = (int) trim((string) $value);

src/Traits/FileValidatorTrait.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ private function proceedToValidate()
119119
// convert size to btyes
120120
$byteToUnit = Tame::byteToUnit(
121121
bytes: $this->config['size'],
122+
format: true,
122123
kb: $this->translation('kb'),
123124
mb: $this->translation('mb'),
124125
gb: $this->translation('gb'),

tests/index3.php

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,38 @@
99

1010
// Env::loadOrFail();
1111

12-
File::name('avatar')
13-
->folder('upload')
14-
->validate()
15-
->save(function($response){
16-
17-
$response
18-
->resize(400, 400)
19-
->watermark('tests/watermark.png', 'top right', 20)
20-
->compress()
21-
;
22-
});
12+
config_file(
13+
config: [
14+
'size' => '3mb',
15+
'baseDir' => '/' // root directory
16+
],
17+
class: [
18+
'error' => 'background: #f7b9b9; margin: 0 auto 50px; width: 100%; max-width: 600px; padding: 20px; font-size: 18px',
19+
'success' => 'background: #c3f9c3; margin: 0 auto 50px; width: 100%; max-width: 600px; padding: 20px; font-size: 18px',
20+
]
21+
);
22+
23+
$upload = File::name('avatar')
24+
->folder('upload')
25+
->generate(false)
26+
->size('10.5mb') // override global settings
27+
->mime('image')
28+
->validate()
29+
->save(function($response){
30+
31+
// dd(
32+
// $response->getConfig(),
33+
// $response->getError(),
34+
// $response->get(),
35+
// tasset("public/{$response->first('path')}", true),
36+
// );
37+
38+
$response
39+
->watermark('tests/watermark.png', 'top right', 20)
40+
->resize(400, 400)
41+
->compress()
42+
;
43+
});
2344

2445
?>
2546

@@ -36,13 +57,25 @@
3657
<form method="post" enctype="multipart/form-data">
3758

3859
<h3 class="valign-wrapper prod_hding_main mb-3">Upload file</h3>
60+
61+
<div style="<?= $upload->getClass(); ?>">
62+
63+
<?php if($upload->hasError()) {?>
64+
<?= $upload->getMessage(); ?>
65+
<?php } elseif($upload->isCompleted()) {?>
66+
<a href="<?= $upload->first('url'); ?>" target="_blank">
67+
Preview Data
68+
</a>
69+
<?php } ?>
70+
71+
</div>
3972

4073
<!--file upload-->
4174
<div class="col-sm-12 mt-3">
4275
<div class="form-group">
4376
<label for="upload">Image</label>
4477
<input type="file" class="form-control-file" id="upload"
45-
name="avatar" multiple>
78+
name="avatar[]" multiple>
4679
</div>
4780
</div>
4881

0 commit comments

Comments
 (0)