|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64178 move_uploaded_file() sometimes executes a copy followed by a move unnecessarily
Submitted: 2013-02-09 02:20 UTC Modified: 2021-05-31 15:59 UTC
Avg. Score:4.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: jbrown at bluedroplet dot com Assigned: cmb (profile)
Status: Wont fix Package: Streams related
PHP Version: 5.4.11 OS: Ubuntu 12.10
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
48 - 36 = ?
Subscribe to this entry?

 [2013-02-09 02:20 UTC] jbrown at bluedroplet dot com
move_uploaded_file() executes a copy followed by a move when stream wrapper URIs are used, even the source and destination are on the same file system



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-02-15 23:14 UTC]
You mean copy followed by a delete? In which case, PHP just calls rename(2) and, if that fails, moves on to copy+delete. Apart from the case where the destination is actually a file:// URL, I don't see any situation where the copy is unnecessary and PHP could detect it. Can you elaborate on that point?
 [2013-02-15 23:14 UTC]
-Status: Open +Status: Feedback
 [2013-02-17 00:22 UTC] jbrown at bluedroplet dot com
I used to run a transcoding server and it would fall over if a 1GB file was uploaded. Pre-resolving the private:// URI before passing it to move_uploaded_file() would prevent this from happening as it would issue a rename instead of a copy followed by a delete.

In general, when moving a file between stream wrappers it makes sense to attempt to resolve them both. If they do both resolve then an rename can be issued instead of a copy followed by a delete. If source and destination are on the same filesystem then this will be extremely cheap.
 [2013-02-17 00:22 UTC] jbrown at bluedroplet dot com
-Status: Feedback +Status: Open
 [2021-05-31 15:59 UTC]
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: cmb
 [2021-05-31 15:59 UTC]
This is not particularly related to move_uploaded_file(), but
rather a general restriction of rename() which is not supported
across wrapper types.  To resolve this on the php-src level,
wrappers would need to know about other wrappers.  I don't think
this will be implemented.

If you still think this situation should be improved, please
pursue the RFC process[1].

[1] <>
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 14 02:01:30 2024 UTC