diff --git a/user_guide_src/source/incoming/incomingrequest.rst b/user_guide_src/source/incoming/incomingrequest.rst index 46ebd35b4bf9..5e77e9253804 100644 --- a/user_guide_src/source/incoming/incomingrequest.rst +++ b/user_guide_src/source/incoming/incomingrequest.rst @@ -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 ` 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 ` for the details. You can retrieve a single file uploaded on its own, based on the filename given in the HTML file input:: diff --git a/user_guide_src/source/libraries/uploaded_files.rst b/user_guide_src/source/libraries/uploaded_files.rst index c38620935060..9640809ba99b 100644 --- a/user_guide_src/source/libraries/uploaded_files.rst +++ b/user_guide_src/source/libraries/uploaded_files.rst @@ -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 ***************