Skip to content

Commit b5cd0d5

Browse files
authored
Merge pull request #6983 from kenjis/fix-docs-uploaded_files.rst
docs: improve uploaded_files.rst
2 parents a68891a + c25430b commit b5cd0d5

2 files changed

Lines changed: 19 additions & 16 deletions

File tree

user_guide_src/source/libraries/uploaded_files.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ request, use ``getFiles()``. This will return an array of files represented by i
126126
Of course, there are multiple ways to name the file input, and anything but the simplest can create strange results.
127127
The array returns in a manner that you would expect. With the simplest usage, a single file might be submitted like::
128128

129-
<input type="file" name="avatar" />
129+
<input type="file" name="avatar">
130130

131131
Which would return a simple array like::
132132

@@ -138,7 +138,7 @@ Which would return a simple array like::
138138

139139
If you used an array notation for the name, the input would look something like::
140140

141-
<input type="file" name="my-form[details][avatar]" />
141+
<input type="file" name="my-form[details][avatar]">
142142

143143
The array returned by ``getFiles()`` would look more like this::
144144

@@ -153,8 +153,8 @@ The array returned by ``getFiles()`` would look more like this::
153153

154154
In some cases, you may specify an array of files to upload::
155155

156-
Upload an avatar: <input type="file" name="my-form[details][avatars][]" />
157-
Upload an avatar: <input type="file" name="my-form[details][avatars][]" />
156+
Upload an avatar: <input type="file" name="my-form[details][avatars][]">
157+
Upload an avatar: <input type="file" name="my-form[details][avatars][]">
158158

159159
In this case, the returned array of files would be more like::
160160

@@ -179,7 +179,7 @@ Simplest usage
179179

180180
With the simplest usage, a single file might be submitted like::
181181

182-
<input type="file" name="userfile" />
182+
<input type="file" name="userfile">
183183

184184
Which would return a simple file instance like:
185185

@@ -190,7 +190,7 @@ Array notation
190190

191191
If you used an array notation for the name, the input would look something like::
192192

193-
<input type="file" name="my-form[details][avatar]" />
193+
<input type="file" name="my-form[details][avatar]">
194194

195195
For get the file instance:
196196

@@ -201,7 +201,7 @@ Multiple files
201201

202202
::
203203

204-
<input type="file" name="images[]" multiple />
204+
<input type="file" name="images[]" multiple>
205205

206206
In controller:
207207

@@ -221,8 +221,8 @@ You might find it easier to use ``getFileMultiple()``, to get an array of upload
221221

222222
Another example::
223223

224-
Upload an avatar: <input type="file" name="my-form[details][avatars][]" />
225-
Upload an avatar: <input type="file" name="my-form[details][avatars][]" />
224+
Upload an avatar: <input type="file" name="my-form[details][avatars][]">
225+
Upload an avatar: <input type="file" name="my-form[details][avatars][]">
226226

227227
In controller:
228228

@@ -334,7 +334,7 @@ Each file can be moved to its new location with the aptly named ``store()`` meth
334334

335335
With the simplest usage, a single file might be submitted like::
336336

337-
<input type="file" name="userfile" />
337+
<input type="file" name="userfile">
338338

339339
By default, upload files are saved in **writable/uploads** directory. The **YYYYMMDD** folder
340340
and random file name will be created. Returns a file path:

user_guide_src/source/libraries/uploaded_files/002.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ public function upload()
1818
$validationRule = [
1919
'userfile' => [
2020
'label' => 'Image File',
21-
'rules' => 'uploaded[userfile]'
22-
. '|is_image[userfile]'
23-
. '|mime_in[userfile,image/jpg,image/jpeg,image/gif,image/png,image/webp]'
24-
. '|max_size[userfile,100]'
25-
. '|max_dims[userfile,1024,768]',
21+
'rules' => [
22+
'uploaded[userfile]',
23+
'is_image[userfile]',
24+
'mime_in[userfile,image/jpg,image/jpeg,image/gif,image/png,image/webp]',
25+
'max_size[userfile,100]',
26+
'max_dims[userfile,1024,768]',
27+
],
2628
],
2729
];
2830
if (! $this->validate($validationRule)) {
@@ -36,10 +38,11 @@ public function upload()
3638
if (! $img->hasMoved()) {
3739
$filepath = WRITEPATH . 'uploads/' . $img->store();
3840

39-
$data = ['uploaded_flleinfo' => new File($filepath)];
41+
$data = ['uploaded_fileinfo' => new File($filepath)];
4042

4143
return view('upload_success', $data);
4244
}
45+
4346
$data = ['errors' => 'The file has already been moved.'];
4447

4548
return view('upload_form', $data);

0 commit comments

Comments
 (0)