From 7b917e0fc6a51117d2386656681ef88b6fe4c83b Mon Sep 17 00:00:00 2001 From: Jake Jackson Date: Thu, 7 Jul 2022 13:53:10 +1000 Subject: [PATCH] Flesh out the README example a little more --- .github/README.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/README.md b/.github/README.md index c705acd..8db5a6a 100644 --- a/.github/README.md +++ b/.github/README.md @@ -39,6 +39,8 @@ When the HTML form is submitted, the server-side PHP code can validate and uploa ```php $storage = new \GravityPdf\Upload\Storage\FileSystem('/path/to/directory'); +// To override existing files when uploading, pass `true` as the second paramter +// $storage = new \GravityPdf\Upload\Storage\FileSystem('/path/to/directory', true); $file = new \GravityPdf\Upload\File('foo', $storage); // Validate file upload @@ -69,7 +71,9 @@ $data = [ // If you have an upload field that accepts multiple files you can access each file's info individually $firstFileName = $file[0]->getNameWithExtension(); -$secondFileName = $file[1]->getNameWithExtension(); +if(isset($file[1])) { + $secondFileName = $file[1]->getNameWithExtension(); +} // or loop over all files for this key foreach($file as $upload) { @@ -82,8 +86,12 @@ try { // Success! $file->upload(); } catch (\Exception $e) { - // Fail! + // Validation errors $errors = $file->getErrors(); + if(count($errors) === 0) { + // Failed for another reason, like the file already exists + $error = $e->getMessage(); + } } ```