Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: improve uploaded_files.rst #7204

Merged
merged 3 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion user_guide_src/source/libraries/uploaded_files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -307,20 +307,46 @@ version, use ``getMimeType()`` instead:
Moving Files
============

with Original Filename
----------------------

Each file can be moved to its new location with the aptly named ``move()`` method. This takes the directory to move
the file to as the first parameter:

.. literalinclude:: uploaded_files/016.php

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

with New Filename
-----------------

You can specify a new filename by passing it as the second parameter:

.. literalinclude:: uploaded_files/017.php

Overwriting Existing File
-------------------------

By default, if the destination file already exists, a new filename will be used.
For example, if **image_name.jpg** already exists in the directory, then the
filename will be **image_name_1.jpg** automatically.

You can overwrite the existing file by passing ``true``
as the third parameter:

.. literalinclude:: uploaded_files/022.php

Check if the File Moved
-----------------------

Once the file has been removed the temporary file is deleted. You can check if a file has been moved already with
the ``hasMoved()`` method, which returns a boolean:

.. literalinclude:: uploaded_files/018.php

When Moving Fails
-----------------

Moving an uploaded file can fail, with an HTTPException, under several circumstances:

- the file has already been moved
Expand Down
3 changes: 3 additions & 0 deletions user_guide_src/source/libraries/uploaded_files/022.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

$file->move(WRITEPATH . 'uploads', null, true);