Skip to content

Commit

Permalink
Merge pull request #5709 from kenjis/fix-docs-incomingrequest.rst
Browse files Browse the repository at this point in the history
docs: fix incorrect description about Uploaded Files in incomingrequest.rst
  • Loading branch information
kenjis committed Feb 19, 2022
2 parents eb09acd + 5010f64 commit e1b4f76
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
19 changes: 3 additions & 16 deletions user_guide_src/source/incoming/incomingrequest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -285,27 +285,14 @@ functions use, so this is a helpful way to "spoof" an incoming request for testi
Uploaded Files
--------------

Information about all uploaded files can be retrieved through ``$request->getFiles()``, which returns a
:doc:`FileCollection </libraries/uploaded_files>` instance. This helps to ease the pain of working with uploaded files,
Information about all uploaded files can be retrieved through ``$request->getFiles()``, which returns an array of
``CodeIgniter\HTTP\Files\UploadedFile`` instance. This helps to ease the pain of working with uploaded files,
and uses best practices to minimize any security risks.
::

$files = $request->getFiles();

// Grab the file by name given in HTML form
if ($files->hasFile('userfile')) {
$file = $files->getFile('userfile');

// Generate a new secure name
$name = $file->getRandomName();

// Move the file to it's new home
$file->move('/path/to/dir', $name);

echo $file->getSize('mb'); // 1.23
echo $file->getExtension(); // jpg
echo $file->getType(); // image/jpg
}
See :ref:`Working with Uploaded Files <uploaded-files-accessing-files>` for the details.

You can retrieve a single file uploaded on its own, based on the filename given in the HTML file input::

Expand Down
2 changes: 2 additions & 0 deletions user_guide_src/source/libraries/uploaded_files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ You should see an upload form. Try uploading an image file (either a
**jpg**, **gif**, **png**, or **webp**). If the path in your controller is correct it should
work.

.. _uploaded-files-accessing-files:

***************
Accessing Files
***************
Expand Down

0 comments on commit e1b4f76

Please sign in to comment.