Skip to content

Commit 7b917e0

Browse files
committed
Flesh out the README example a little more
1 parent 5e6f796 commit 7b917e0

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

.github/README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ When the HTML form is submitted, the server-side PHP code can validate and uploa
3939

4040
```php
4141
$storage = new \GravityPdf\Upload\Storage\FileSystem('/path/to/directory');
42+
// To override existing files when uploading, pass `true` as the second paramter
43+
// $storage = new \GravityPdf\Upload\Storage\FileSystem('/path/to/directory', true);
4244
$file = new \GravityPdf\Upload\File('foo', $storage);
4345

4446
// Validate file upload
@@ -69,7 +71,9 @@ $data = [
6971

7072
// If you have an upload field that accepts multiple files you can access each file's info individually
7173
$firstFileName = $file[0]->getNameWithExtension();
72-
$secondFileName = $file[1]->getNameWithExtension();
74+
if(isset($file[1])) {
75+
$secondFileName = $file[1]->getNameWithExtension();
76+
}
7377

7478
// or loop over all files for this key
7579
foreach($file as $upload) {
@@ -82,8 +86,12 @@ try {
8286
// Success!
8387
$file->upload();
8488
} catch (\Exception $e) {
85-
// Fail!
89+
// Validation errors
8690
$errors = $file->getErrors();
91+
if(count($errors) === 0) {
92+
// Failed for another reason, like the file already exists
93+
$error = $e->getMessage();
94+
}
8795
}
8896
```
8997

0 commit comments

Comments
 (0)