Skip to content

Commit ac2f64f

Browse files
committed
docs: fix typo and docs of uploaded_files.
1 parent f59babb commit ac2f64f

2 files changed

Lines changed: 28 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: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/**
4+
* This file is part of CodeIgniter 4 framework.
5+
*
6+
* (c) CodeIgniter Foundation <admin@codeigniter.com>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
312
namespace App\Controllers;
413

514
use CodeIgniter\Files\File;
@@ -18,11 +27,13 @@ public function upload()
1827
$validationRule = [
1928
'userfile' => [
2029
'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]',
30+
'rules' => [
31+
'uploaded[userfile]',
32+
'is_image[userfile]',
33+
'mime_in[userfile,image/jpg,image/jpeg,image/gif,image/png,image/webp]',
34+
'max_size[userfile,100]',
35+
'max_dims[userfile,1024,768]',
36+
],
2637
],
2738
];
2839
if (! $this->validate($validationRule)) {
@@ -36,10 +47,11 @@ public function upload()
3647
if (! $img->hasMoved()) {
3748
$filepath = WRITEPATH . 'uploads/' . $img->store();
3849

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

4152
return view('upload_success', $data);
4253
}
54+
4355
$data = ['errors' => 'The file has already been moved.'];
4456

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

0 commit comments

Comments
 (0)