Skip to content

Commit

Permalink
Merge pull request #9065 from kenjis/docs-files.rst
Browse files Browse the repository at this point in the history
docs: improve files.rst
  • Loading branch information
kenjis authored Jul 25, 2024
2 parents 1192b91 + 5340d8d commit 5fc03b7
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions user_guide_src/source/libraries/files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@ Getting a File instance
***********************

You create a new File instance by passing in the path to the file in the constructor.
By default, the file does not need to exist. However, you can pass an additional argument of "true"
to check that the file exists and throw ``FileNotFoundException()`` if it does not.

.. literalinclude:: files/001.php
:lines: 2-

By default, the file does not need to exist. However, you can pass an additional argument of ``true``
to check that the file exists and throw ``FileNotFoundException()`` if it does not.

Taking Advantage of Spl
***********************

Once you have an instance, you have the full power of the SplFileInfo class at the ready, including:

.. literalinclude:: files/002.php
:lines: 2-

New Features
************
Expand All @@ -38,21 +41,24 @@ You can generate a cryptographically secure random filename, with the current ti
method. This is especially useful to rename files when moving it so that the filename is unguessable:

.. literalinclude:: files/003.php
:lines: 2-

getSize()
=========

Returns the size of the uploaded file in bytes:
Returns the size of the file in bytes:

.. literalinclude:: files/004.php
:lines: 2-

getSizeByUnit()
===============

Returns the size of the uploaded file default in bytes. You can pass in either 'kb' or 'mb' as the first parameter to get
Returns the size of the file default in bytes. You can pass in either ``'kb'`` or ``'mb'`` as the first parameter to get
the results in kilobytes or megabytes, respectively:

.. literalinclude:: files/005.php
:lines: 2-

getMimeType()
=============
Expand All @@ -61,6 +67,7 @@ Retrieve the media type (mime type) of the file. Uses methods that are considere
the type of file:

.. literalinclude:: files/006.php
:lines: 2-

guessExtension()
================
Expand All @@ -70,6 +77,7 @@ will return null. This is often a more trusted source than simply using the exte
the values in **app/Config/Mimes.php** to determine extension:

.. literalinclude:: files/007.php
:lines: 2-

Moving Files
============
Expand All @@ -78,12 +86,15 @@ Each file can be moved to its new location with the aptly named ``move()`` metho
the file to as the first parameter:

.. literalinclude:: files/008.php
:lines: 2-

By default, the original filename was used. You can specify a new filename by passing it as the second parameter:

.. literalinclude:: files/009.php
:lines: 2-

The move() method returns a new File instance that for the relocated file, so you must capture the result if the
The ``move()`` method returns a new File instance that for the relocated file, so you must capture the result if the
resulting location is needed:

.. literalinclude:: files/010.php
:lines: 2-

0 comments on commit 5fc03b7

Please sign in to comment.