I have read on a PHP's website that file_put_contents
is not atomic. I was planning to use that to upload a file.
I was then wondering about the atomicity of move_uploaded_file
, but could not find any information.
Any help?
Thanks.
I have read on a PHP's website that file_put_contents
is not atomic. I was planning to use that to upload a file.
I was then wondering about the atomicity of move_uploaded_file
, but could not find any information.
Any help?
Thanks.
I'm assuming you mean atomic at a file-system level. It comes down to depending on your filesystem.
The process that happens with move_uploaded_files
is basically:
open_basedir
allow writing to the destination?Assuming all of those return a yes, then a rename
is tried. On most filesystems, a rename is atomic.
If the rename
failed, a copy and delete is then tried. This isn't atomic, as copying requires reading and then there's a separate delete.
Finally, if neither the rename nor the copy worked, an error is generated instead.