Skip to content

Commit c475127

Browse files
authored
Merge pull request #7204 from kenjis/docs-uploaded_files.rst
docs: improve uploaded_files.rst
2 parents 225eaae + eeb0489 commit c475127

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

user_guide_src/source/libraries/uploaded_files.rst

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,20 +307,46 @@ version, use ``getMimeType()`` instead:
307307
Moving Files
308308
============
309309

310+
with Original Filename
311+
----------------------
312+
310313
Each file can be moved to its new location with the aptly named ``move()`` method. This takes the directory to move
311314
the file to as the first parameter:
312315

313316
.. literalinclude:: uploaded_files/016.php
314317

315-
By default, the original filename was used. You can specify a new filename by passing it as the second parameter:
318+
By default, the original filename was used.
319+
320+
with New Filename
321+
-----------------
322+
323+
You can specify a new filename by passing it as the second parameter:
316324

317325
.. literalinclude:: uploaded_files/017.php
318326

327+
Overwriting Existing File
328+
-------------------------
329+
330+
By default, if the destination file already exists, a new filename will be used.
331+
For example, if **image_name.jpg** already exists in the directory, then the
332+
filename will be **image_name_1.jpg** automatically.
333+
334+
You can overwrite the existing file by passing ``true``
335+
as the third parameter:
336+
337+
.. literalinclude:: uploaded_files/022.php
338+
339+
Check if the File Moved
340+
-----------------------
341+
319342
Once the file has been removed the temporary file is deleted. You can check if a file has been moved already with
320343
the ``hasMoved()`` method, which returns a boolean:
321344

322345
.. literalinclude:: uploaded_files/018.php
323346

347+
When Moving Fails
348+
-----------------
349+
324350
Moving an uploaded file can fail, with an HTTPException, under several circumstances:
325351

326352
- the file has already been moved
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
$file->move(WRITEPATH . 'uploads', null, true);

0 commit comments

Comments
 (0)