From 5cd7ff266f1a0a4d1fda40700c6e20ed99b31b13 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 9 May 2024 10:24:16 +0900 Subject: [PATCH 1/5] docs: break long lines --- user_guide_src/source/libraries/uploaded_files.rst | 6 ++++-- user_guide_src/source/libraries/validation.rst | 7 ++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/user_guide_src/source/libraries/uploaded_files.rst b/user_guide_src/source/libraries/uploaded_files.rst index 118af85e86ee..fab3b714d76c 100644 --- a/user_guide_src/source/libraries/uploaded_files.rst +++ b/user_guide_src/source/libraries/uploaded_files.rst @@ -2,8 +2,10 @@ Working with Uploaded Files ########################### -CodeIgniter makes working with files uploaded through a form much simpler and more secure than using PHP's ``$_FILES`` -array directly. This extends the :doc:`File class ` and thus gains all of the features of that class. +CodeIgniter makes working with files uploaded through a form much simpler and +more secure than using PHP's ``$_FILES`` array directly. This extends the +:doc:`File class ` and thus gains all of the features of that +class. .. note:: This is not the same as the File Uploading class in CodeIgniter 3. This provides a raw interface to the uploaded files with a few small features. diff --git a/user_guide_src/source/libraries/validation.rst b/user_guide_src/source/libraries/validation.rst index 19f0e0058a31..8fa91533c16b 100644 --- a/user_guide_src/source/libraries/validation.rst +++ b/user_guide_src/source/libraries/validation.rst @@ -1044,9 +1044,10 @@ file validation. files. Therefore, adding any general rules, like ``permit_empty``, to file validation rules array or string, the file validation will not work correctly. -Since the value of a file upload HTML field doesn't exist, and is stored in the ``$_FILES`` global, the name of the input field will -need to be used twice. Once to specify the field name as you would for any other rule, but again as the first parameter of all -file upload related rules:: +Since the value of a file upload HTML field doesn't exist, and is stored in the +``$_FILES`` global, the name of the input field will need to be used twice. Once +to specify the field name as you would for any other rule, but again as the first +parameter of all file upload related rules:: // In the HTML From 251f3aacea47b75f385073430ecc797e2f067510 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 9 May 2024 10:32:02 +0900 Subject: [PATCH 2/5] chore: change section title --- user_guide_src/source/libraries/uploaded_files.rst | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/user_guide_src/source/libraries/uploaded_files.rst b/user_guide_src/source/libraries/uploaded_files.rst index fab3b714d76c..7dd9ef5d6988 100644 --- a/user_guide_src/source/libraries/uploaded_files.rst +++ b/user_guide_src/source/libraries/uploaded_files.rst @@ -14,9 +14,11 @@ class. :local: :depth: 2 -*********** -The Process -*********** +.. _file-upload-form-tutorial: + +************************* +File Upload Form Tutorial +************************* Uploading a file involves the following general process: From 2c5b554d8ef88327700cae8a1163fb39e39d5503 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 9 May 2024 10:54:37 +0900 Subject: [PATCH 3/5] docs: remove unnecessary / in directory paths --- user_guide_src/source/libraries/uploaded_files.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/user_guide_src/source/libraries/uploaded_files.rst b/user_guide_src/source/libraries/uploaded_files.rst index 7dd9ef5d6988..d2928bc4aa99 100644 --- a/user_guide_src/source/libraries/uploaded_files.rst +++ b/user_guide_src/source/libraries/uploaded_files.rst @@ -37,7 +37,7 @@ Creating the Upload Form ======================== Using a text editor, create a form called **upload_form.php**. In it, place -this code and save it to your **app/Views/** directory: +this code and save it to your **app/Views** directory: .. literalinclude:: uploaded_files/001.php @@ -51,7 +51,7 @@ The Success Page ================ Using a text editor, create a form called **upload_success.php**. In it, -place this code and save it to your **app/Views/** directory:: +place this code and save it to your **app/Views** directory:: @@ -77,7 +77,7 @@ The Controller ============== Using a text editor, create a controller called **Upload.php**. In it, place -this code and save it to your **app/Controllers/** directory: +this code and save it to your **app/Controllers** directory: .. literalinclude:: uploaded_files/002.php From 28ed8c9253e12a7d3398290070c5a2d9ebfaaec8 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 9 May 2024 10:55:49 +0900 Subject: [PATCH 4/5] docs: add empty line --- user_guide_src/source/libraries/uploaded_files.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/user_guide_src/source/libraries/uploaded_files.rst b/user_guide_src/source/libraries/uploaded_files.rst index d2928bc4aa99..ec139b59ae64 100644 --- a/user_guide_src/source/libraries/uploaded_files.rst +++ b/user_guide_src/source/libraries/uploaded_files.rst @@ -43,7 +43,9 @@ this code and save it to your **app/Views** directory: You'll notice we are using a form helper to create the opening form tag. File uploads require a multipart form, so the helper creates the proper -syntax for you. You'll also notice we have an ``$errors`` variable. This is +syntax for you. + +You'll also notice we have an ``$errors`` variable. This is so we can show error messages in the event the user does something wrong. From 312a951ed4029cf2308432b9eb65f1259345ffe5 Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 9 May 2024 10:56:06 +0900 Subject: [PATCH 5/5] docs: add descriptions --- .../source/libraries/uploaded_files.rst | 16 +++++++++++++--- user_guide_src/source/libraries/validation.rst | 4 ++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/user_guide_src/source/libraries/uploaded_files.rst b/user_guide_src/source/libraries/uploaded_files.rst index ec139b59ae64..ef1bc6b592f6 100644 --- a/user_guide_src/source/libraries/uploaded_files.rst +++ b/user_guide_src/source/libraries/uploaded_files.rst @@ -83,9 +83,19 @@ this code and save it to your **app/Controllers** directory: .. literalinclude:: uploaded_files/002.php -.. note:: Since the value of a file upload HTML field doesn't exist, and is stored in the ``$_FILES`` global, - only :ref:`rules-for-file-uploads` can be used to validate upload file with :doc:`validation`. - The rule ``required`` also can't be used, so use ``uploaded`` instead. +Since the value of a file upload HTML field doesn't exist, and is stored in the +``$_FILES`` global, only :ref:`rules-for-file-uploads` can be used to validate +upload file with :doc:`validation`. + +The rule ``required`` cannot be used either, so if the file is required, use +the rule ``uploaded`` instead. + +Note that an empty array (``[]``) is passed as the first argument to +``$this->validateData()``. It is because the file validation rules get the data +for the uploaded file directly from the Request object. + +If the form has fields other than file upload, pass the field data as the first +argument. The Routes ========== diff --git a/user_guide_src/source/libraries/validation.rst b/user_guide_src/source/libraries/validation.rst index 8fa91533c16b..3b16ad588d87 100644 --- a/user_guide_src/source/libraries/validation.rst +++ b/user_guide_src/source/libraries/validation.rst @@ -885,6 +885,8 @@ Available Rules .. literalinclude:: validation/038.php :lines: 2- +.. _rules-for-general-use: + Rules for General Use ===================== @@ -1057,6 +1059,8 @@ parameter of all file upload related rules:: 'avatar' => 'uploaded[avatar]|max_size[avatar,1024]', ]); +See also :ref:`file-upload-form-tutorial`. + ======================= ========== ============================================= =================================================== Rule Parameter Description Example ======================= ========== ============================================= ===================================================