You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$data = ['uploaded_flleinfo' => new File($filepath)];
139
+
140
+
return view('upload_success', $data);
141
+
} else {
142
+
$data = ['errors' => 'The file has already been moved.'];
143
+
144
+
return view('upload_form', $data);
145
+
}
146
+
}
147
+
}
148
+
149
+
The Upload Directory
150
+
====================
151
+
152
+
The uploaded files are stored in the **writable/uploads/** directory.
153
+
154
+
Try it!
155
+
=======
156
+
157
+
To try your form, visit your site using a URL similar to this one::
158
+
159
+
example.com/index.php/upload/
160
+
161
+
You should see an upload form. Try uploading an image file (either a
162
+
**jpg**, **gif**, **png**, or **webp**). If the path in your controller is correct it should
163
+
work.
164
+
165
+
***************
16
166
Accessing Files
17
-
===============
167
+
***************
18
168
19
169
All Files
20
-
----------
170
+
=========
21
171
22
172
When you upload files they can be accessed natively in PHP through the ``$_FILES`` superglobal. This array has some
23
173
major shortcomings when working with multiple files uploaded at once, and has potential security flaws many developers
@@ -72,7 +222,7 @@ In this case, the returned array of files would be more like::
72
222
]
73
223
74
224
Single File
75
-
-----------
225
+
===========
76
226
77
227
If you just need to access a single file, you can use ``getFile()`` to retrieve the file instance directly. This will return an instance of ``CodeIgniter\HTTP\Files\UploadedFile``:
78
228
@@ -140,15 +290,15 @@ In controller::
140
290
141
291
.. note:: Using ``getFiles()`` is more appropriate.
142
292
143
-
=====================
293
+
*********************
144
294
Working With the File
145
-
=====================
295
+
*********************
146
296
147
297
Once you've retrieved the UploadedFile instance, you can retrieve information about the file in safe ways, as well as
148
298
move the file to a new location.
149
299
150
300
Verify A File
151
-
-------------
301
+
=============
152
302
153
303
You can check that a file was actually uploaded via HTTP with no errors by calling the ``isValid()`` method::
154
304
@@ -169,7 +319,7 @@ this method:
169
319
* File upload was stopped by a PHP extension.
170
320
171
321
File Names
172
-
----------
322
+
==========
173
323
174
324
**getName()**
175
325
@@ -192,7 +342,7 @@ To get the full path of the temp file that was created during the upload, you ca
192
342
$tempfile = $file->getTempName();
193
343
194
344
Other File Info
195
-
---------------
345
+
===============
196
346
197
347
**getClientExtension()**
198
348
@@ -212,7 +362,7 @@ version, use ``getMimeType()`` instead::
212
362
echo $type; // image/png
213
363
214
364
Moving Files
215
-
------------
365
+
============
216
366
217
367
Each file can be moved to its new location with the aptly named ``move()`` method. This takes the directory to move
218
368
the file to as the first parameter::
@@ -238,7 +388,7 @@ Moving an uploaded file can fail, with an HTTPException, under several circumsta
238
388
- the file move operation fails (e.g., improper permissions)
239
389
240
390
Store Files
241
-
------------
391
+
===========
242
392
243
393
Each file can be moved to its new location with the aptly named ``store()`` method.
0 commit comments